fix: dont count session events for current billing period

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-11-12 14:54:09 +01:00
parent 723ba3ef6c
commit e613a4e01c
2 changed files with 3 additions and 1 deletions

View File

@@ -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;

View File

@@ -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;
}; };