prep events partition
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
getChartSql,
|
||||
getEventFiltersWhereClause,
|
||||
getProfiles,
|
||||
TABLE_NAMES,
|
||||
} from '@openpanel/db';
|
||||
import type {
|
||||
FinalChart,
|
||||
@@ -293,7 +294,7 @@ export async function getFunnelData({
|
||||
const innerSql = `SELECT
|
||||
session_id,
|
||||
windowFunnel(${ONE_DAY_IN_SECONDS})(toUnixTimestamp(created_at), ${funnels.join(', ')}) AS level
|
||||
FROM events
|
||||
FROM ${TABLE_NAMES.events}
|
||||
WHERE
|
||||
project_id = ${escape(projectId)} AND
|
||||
created_at >= '${formatClickhouseDate(startDate)}' AND
|
||||
@@ -306,7 +307,7 @@ export async function getFunnelData({
|
||||
const [funnelRes, sessionRes] = await Promise.all([
|
||||
chQuery<{ level: number; count: number }>(sql),
|
||||
chQuery<{ count: number }>(
|
||||
`SELECT count(name) as count FROM events WHERE project_id = ${escape(projectId)} AND name = 'session_start' AND (created_at >= '${formatClickhouseDate(startDate)}') AND (created_at <= '${formatClickhouseDate(endDate)}')`
|
||||
`SELECT count(name) as count FROM ${TABLE_NAMES.events} WHERE project_id = ${escape(projectId)} AND name = 'session_start' AND (created_at >= '${formatClickhouseDate(startDate)}') AND (created_at <= '${formatClickhouseDate(endDate)}')`
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -409,7 +410,7 @@ export async function getFunnelStep({
|
||||
const innerSql = `SELECT
|
||||
session_id,
|
||||
windowFunnel(${ONE_DAY_IN_SECONDS})(toUnixTimestamp(created_at), ${funnels.join(', ')}) AS level
|
||||
FROM events
|
||||
FROM ${TABLE_NAMES.events}
|
||||
WHERE
|
||||
project_id = ${escape(projectId)} AND
|
||||
created_at >= '${formatClickhouseDate(startDate)}' AND
|
||||
@@ -421,7 +422,7 @@ export async function getFunnelStep({
|
||||
SELECT
|
||||
DISTINCT e.profile_id as id
|
||||
FROM sessions s
|
||||
JOIN events e ON s.session_id = e.session_id
|
||||
JOIN ${TABLE_NAMES.events} e ON s.session_id = e.session_id
|
||||
WHERE
|
||||
s.level = ${step} AND
|
||||
e.project_id = ${escape(projectId)} AND
|
||||
|
||||
@@ -3,7 +3,7 @@ import { escape } from 'sqlstring';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { average, max, min, round, slug, sum } from '@openpanel/common';
|
||||
import { chQuery, createSqlBuilder, db } from '@openpanel/db';
|
||||
import { chQuery, createSqlBuilder, db, TABLE_NAMES } from '@openpanel/db';
|
||||
import { zChartInput } from '@openpanel/validation';
|
||||
import type {
|
||||
FinalChart,
|
||||
@@ -17,7 +17,6 @@ import { createTRPCRouter, protectedProcedure, publicProcedure } from '../trpc';
|
||||
import {
|
||||
getChart,
|
||||
getChartPrevStartEndDate,
|
||||
getChartSeries,
|
||||
getChartStartEndDate,
|
||||
getFunnelData,
|
||||
getFunnelStep,
|
||||
@@ -28,7 +27,7 @@ export const chartRouter = createTRPCRouter({
|
||||
.input(z.object({ projectId: z.string() }))
|
||||
.query(async ({ input: { projectId } }) => {
|
||||
const events = await chQuery<{ name: string }>(
|
||||
`SELECT DISTINCT name FROM events WHERE project_id = ${escape(projectId)}`
|
||||
`SELECT DISTINCT name FROM ${TABLE_NAMES.events} WHERE project_id = ${escape(projectId)}`
|
||||
);
|
||||
|
||||
return [
|
||||
@@ -43,7 +42,7 @@ export const chartRouter = createTRPCRouter({
|
||||
.input(z.object({ event: z.string().optional(), projectId: z.string() }))
|
||||
.query(async ({ input: { projectId, event } }) => {
|
||||
const events = await chQuery<{ keys: string[] }>(
|
||||
`SELECT distinct mapKeys(properties) as keys from events where ${
|
||||
`SELECT distinct mapKeys(properties) as keys from ${TABLE_NAMES.events} where ${
|
||||
event && event !== '*' ? `name = ${escape(event)} AND ` : ''
|
||||
} project_id = ${escape(projectId)};`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user