Refactored startDate usage.
This commit is contained in:
@@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
||||
import { max } from 'date-fns';
|
||||
|
||||
export async function getWebsiteDateRange(...args: [websiteId: string]) {
|
||||
return runQuery({
|
||||
@@ -40,8 +41,8 @@ async function clickhouseQuery(websiteId: string) {
|
||||
max(created_at) as max
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at >= {dataStartDate:DateTime}
|
||||
and created_at >= {startDate:DateTime}
|
||||
`,
|
||||
{ websiteId, dataStartDate: website.dataStartDate },
|
||||
{ websiteId, startDate: max([new Date('2000-01-01'), website.resetAt]) },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { max } from 'date-fns';
|
||||
|
||||
export async function getWebsiteStats(
|
||||
...args: [
|
||||
@@ -44,7 +45,6 @@ async function relationalQuery(
|
||||
${joinSession}
|
||||
where event_type = {{eventType}}
|
||||
and website.website_id = {{websiteId::uuid}}
|
||||
and website_event.created_at >= {{dataStartDate}}
|
||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||
${filterQuery}
|
||||
group by 1, 2
|
||||
@@ -53,9 +53,8 @@ async function relationalQuery(
|
||||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
endDate,
|
||||
dataStartDate: website.dataStartDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
);
|
||||
@@ -86,7 +85,6 @@ async function clickhouseQuery(
|
||||
max(created_at) max_time
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at >= {dataStartDate:DateTime}
|
||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||
and event_type = {eventType:UInt32}
|
||||
${filterQuery}
|
||||
@@ -96,9 +94,8 @@ async function clickhouseQuery(
|
||||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
endDate,
|
||||
dataStartDate: website.dataStartDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user