fix: try fix revenue issues on overview

This commit is contained in:
Carl-Gerhard Lindesvärd
2026-02-05 22:54:30 +00:00
parent 063e80a659
commit b0d531d793

View File

@@ -5,9 +5,16 @@ import { type IChartEventFilter, zTimeInterval } from '@openpanel/validation';
import { omit } from 'ramda'; import { omit } from 'ramda';
import sqlstring from 'sqlstring'; import sqlstring from 'sqlstring';
import { z } from 'zod'; import { z } from 'zod';
import { TABLE_NAMES, ch } from '../clickhouse/client'; import {
TABLE_NAMES,
ch,
convertClickhouseDateToJs,
} from '../clickhouse/client';
import { clix } from '../clickhouse/query-builder'; import { clix } from '../clickhouse/query-builder';
import { getEventFiltersWhereClause, getSelectPropertyKey } from './chart.service'; import {
getEventFiltersWhereClause,
getSelectPropertyKey,
} from './chart.service';
// Constants // Constants
const ROLLUP_DATE_PREFIX = '1970-01-01'; const ROLLUP_DATE_PREFIX = '1970-01-01';
@@ -221,7 +228,7 @@ export class OverviewService {
.groupBy(['date']) .groupBy(['date'])
.rollup() .rollup()
.transform({ .transform({
date: (item) => new Date(item.date).toISOString(), date: (item) => convertClickhouseDateToJs(item.date).toISOString(),
}); });
} }
@@ -1288,10 +1295,7 @@ export class OverviewService {
: ''; : '';
const query = clix(this.client, timezone) const query = clix(this.client, timezone)
.select<{ name: string; count: number }>([ .select<{ name: string; count: number }>(['name', 'count() as count'])
'name',
'count() as count',
])
.from(TABLE_NAMES.events, false) .from(TABLE_NAMES.events, false)
.where('project_id', '=', projectId) .where('project_id', '=', projectId)
.where('created_at', 'BETWEEN', [ .where('created_at', 'BETWEEN', [
@@ -1379,9 +1383,9 @@ export class OverviewService {
city: string | null; city: string | null;
count: number; count: number;
}>([ }>([
'nullIf(country, \'\') as country', "nullIf(country, '') as country",
'nullIf(region, \'\') as region', "nullIf(region, '') as region",
'nullIf(city, \'\') as city', "nullIf(city, '') as city",
'uniq(session_id) as count', 'uniq(session_id) as count',
]) ])
.from(TABLE_NAMES.events, false) .from(TABLE_NAMES.events, false)
@@ -1391,7 +1395,7 @@ export class OverviewService {
clix.datetime(endDate, 'toDateTime'), clix.datetime(endDate, 'toDateTime'),
]) ])
.rawWhere(where) .rawWhere(where)
.rawWhere('country IS NOT NULL AND country != \'\'') .rawWhere("country IS NOT NULL AND country != ''")
.groupBy(['country', 'region', 'city']) .groupBy(['country', 'region', 'city'])
.orderBy('count', 'DESC') .orderBy('count', 'DESC')
.limit(MAX_RECORDS_LIMIT); .limit(MAX_RECORDS_LIMIT);