fix: dont count session events for current billing period
This commit is contained in:
@@ -218,6 +218,7 @@ export async function getOrganizationBillingEventsCount(
|
|||||||
sb.select.count = 'COUNT(*) AS count';
|
sb.select.count = 'COUNT(*) AS count';
|
||||||
sb.where.projectIds = `project_id IN (${organization.projects.map((project) => sqlstring.escape(project.id)).join(',')})`;
|
sb.where.projectIds = `project_id IN (${organization.projects.map((project) => sqlstring.escape(project.id)).join(',')})`;
|
||||||
sb.where.createdAt = `created_at BETWEEN ${sqlstring.escape(formatClickhouseDate(organization.subscriptionCurrentPeriodStart))} AND ${sqlstring.escape(formatClickhouseDate(organization.subscriptionCurrentPeriodEnd))}`;
|
sb.where.createdAt = `created_at BETWEEN ${sqlstring.escape(formatClickhouseDate(organization.subscriptionCurrentPeriodStart))} AND ${sqlstring.escape(formatClickhouseDate(organization.subscriptionCurrentPeriodEnd))}`;
|
||||||
|
sb.where.names = `name NOT IN ('session_start', 'session_end')`;
|
||||||
|
|
||||||
const res = await chQuery<{ count: number }>(getSql());
|
const res = await chQuery<{ count: number }>(getSql());
|
||||||
return res[0]?.count;
|
return res[0]?.count;
|
||||||
@@ -242,6 +243,7 @@ export async function getOrganizationBillingEventsCountSerie(
|
|||||||
sb.orderBy.day = `${interval} WITH FILL FROM toDate(${sqlstring.escape(formatClickhouseDate(startDate, true))}) TO toDate(${sqlstring.escape(formatClickhouseDate(endDate, true))}) STEP INTERVAL 1 ${interval.toUpperCase()}`;
|
sb.orderBy.day = `${interval} WITH FILL FROM toDate(${sqlstring.escape(formatClickhouseDate(startDate, true))}) TO toDate(${sqlstring.escape(formatClickhouseDate(endDate, true))}) STEP INTERVAL 1 ${interval.toUpperCase()}`;
|
||||||
sb.where.projectIds = `project_id IN (${organization.projects.map((project) => sqlstring.escape(project.id)).join(',')})`;
|
sb.where.projectIds = `project_id IN (${organization.projects.map((project) => sqlstring.escape(project.id)).join(',')})`;
|
||||||
sb.where.createdAt = `${interval} BETWEEN ${sqlstring.escape(formatClickhouseDate(startDate, true))} AND ${sqlstring.escape(formatClickhouseDate(endDate, true))}`;
|
sb.where.createdAt = `${interval} BETWEEN ${sqlstring.escape(formatClickhouseDate(startDate, true))} AND ${sqlstring.escape(formatClickhouseDate(endDate, true))}`;
|
||||||
|
sb.where.names = `name NOT IN ('session_start', 'session_end')`;
|
||||||
|
|
||||||
const res = await chQuery<{ count: number; day: string }>(getSql());
|
const res = await chQuery<{ count: number; day: string }>(getSql());
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export async function getProjects({
|
|||||||
|
|
||||||
export const getProjectEventsCount = async (projectId: string) => {
|
export const getProjectEventsCount = async (projectId: string) => {
|
||||||
const res = await chQuery<{ count: number }>(
|
const res = await chQuery<{ count: number }>(
|
||||||
`SELECT count(*) as count FROM ${TABLE_NAMES.events} WHERE project_id = ${sqlstring.escape(projectId)}`,
|
`SELECT count(*) as count FROM ${TABLE_NAMES.events} WHERE project_id = ${sqlstring.escape(projectId)} AND name NOT IN ('session_start', 'session_end')`,
|
||||||
);
|
);
|
||||||
return res[0]?.count;
|
return res[0]?.count;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user