mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-07 01:45:43 +01:00
Refactored startDate usage.
This commit is contained in:
parent
0f98fb5959
commit
a0aaeeeb57
@ -1,9 +1,8 @@
|
|||||||
import cache from 'lib/cache';
|
import cache from 'lib/cache';
|
||||||
import { getWebsite, getSession, getUser } from 'queries';
|
import { getWebsite, getSession, getUser } from 'queries';
|
||||||
import { User, Website, Session } from '@prisma/client';
|
import { User, Website, Session } from '@prisma/client';
|
||||||
import { DEFAULT_RESET_DATE } from './constants';
|
|
||||||
|
|
||||||
export async function loadWebsite(websiteId: string): Promise<Website & { dataStartDate: Date }> {
|
export async function loadWebsite(websiteId: string): Promise<Website> {
|
||||||
let website;
|
let website;
|
||||||
|
|
||||||
if (cache.enabled) {
|
if (cache.enabled) {
|
||||||
@ -12,8 +11,6 @@ export async function loadWebsite(websiteId: string): Promise<Website & { dataSt
|
|||||||
website = await getWebsite({ id: websiteId });
|
website = await getWebsite({ id: websiteId });
|
||||||
}
|
}
|
||||||
|
|
||||||
website.dataStartDate = new Date(website?.resetAt || DEFAULT_RESET_DATE);
|
|
||||||
|
|
||||||
if (!website || website.deletedAt) {
|
if (!website || website.deletedAt) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
|||||||
import { WebsiteEventDataFields } from 'lib/types';
|
import { WebsiteEventDataFields } from 'lib/types';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
||||||
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getEventDataEvents(
|
export async function getEventDataEvents(
|
||||||
...args: [
|
...args: [
|
||||||
@ -42,13 +43,12 @@ async function relationalQuery(
|
|||||||
on we.event_id = ed.website_event_id
|
on we.event_id = ed.website_event_id
|
||||||
where ed.website_id = {{websiteId:uuid}}
|
where ed.website_id = {{websiteId:uuid}}
|
||||||
and ed.event_key = {{field}}
|
and ed.event_key = {{field}}
|
||||||
and ed.created_at >= {{dataStartDate}}
|
|
||||||
and ed.created_at between {{startDate}} and {{endDate}}
|
and ed.created_at between {{startDate}} and {{endDate}}
|
||||||
and we.event_name = {{event}}
|
and we.event_name = {{event}}
|
||||||
group by ed.event_key, ed.string_value
|
group by ed.event_key, ed.string_value
|
||||||
order by 3 desc, 2 desc, 1 asc
|
order by 3 desc, 2 desc, 1 asc
|
||||||
`,
|
`,
|
||||||
{ ...filters, websiteId, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ ...filters, websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
@ -63,12 +63,11 @@ async function relationalQuery(
|
|||||||
on we.event_id = ed.website_event_id
|
on we.event_id = ed.website_event_id
|
||||||
where ed.website_id = {{websiteId::uuid}}
|
where ed.website_id = {{websiteId::uuid}}
|
||||||
and ed.event_key = {{field}}
|
and ed.event_key = {{field}}
|
||||||
and ed.created_at >= {{dataStartDate}}
|
|
||||||
and ed.created_at between {{startDate}} and {{endDate}}
|
and ed.created_at between {{startDate}} and {{endDate}}
|
||||||
group by we.event_name, ed.event_key, ed.string_value
|
group by we.event_name, ed.event_key, ed.string_value
|
||||||
order by 3 desc, 2 desc, 1 asc
|
order by 3 desc, 2 desc, 1 asc
|
||||||
`,
|
`,
|
||||||
{ websiteId, field, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ websiteId, field, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,14 +92,13 @@ async function clickhouseQuery(
|
|||||||
count(*) as total
|
count(*) as total
|
||||||
from event_data
|
from event_data
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
and event_name = {event:String}
|
and event_name = {event:String}
|
||||||
group by event_key, data_type, string_value, event_name
|
group by event_key, data_type, string_value, event_name
|
||||||
order by 1 asc, 2 asc, 3 asc, 4 desc
|
order by 1 asc, 2 asc, 3 asc, 4 desc
|
||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
{ ...filters, websiteId, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ ...filters, websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,12 +111,11 @@ async function clickhouseQuery(
|
|||||||
count(*) as total
|
count(*) as total
|
||||||
from event_data
|
from event_data
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
group by event_key, data_type, event_name
|
group by event_key, data_type, event_name
|
||||||
order by 1 asc, 2 asc
|
order by 1 asc, 2 asc
|
||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
{ websiteId, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import clickhouse from 'lib/clickhouse';
|
|||||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||||
import { WebsiteEventDataFields } from 'lib/types';
|
import { WebsiteEventDataFields } from 'lib/types';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getEventDataFields(
|
export async function getEventDataFields(
|
||||||
...args: [websiteId: string, startDate: Date, endDate: Date, field?: string]
|
...args: [websiteId: string, startDate: Date, endDate: Date, field?: string]
|
||||||
@ -28,13 +28,12 @@ async function relationalQuery(websiteId: string, startDate: Date, endDate: Date
|
|||||||
from event_data
|
from event_data
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_id = {{websiteId::uuid}}
|
||||||
and event_key = {{field}}
|
and event_key = {{field}}
|
||||||
and created_at >= {{dataStartDate}}
|
|
||||||
and created_at between {{startDate}} and {{endDate}}
|
and created_at between {{startDate}} and {{endDate}}
|
||||||
group by event_key, string_value
|
group by event_key, string_value
|
||||||
order by 3 desc, 2 desc, 1 asc
|
order by 3 desc, 2 desc, 1 asc
|
||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
{ websiteId, field, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ websiteId, field, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,13 +45,12 @@ async function relationalQuery(websiteId: string, startDate: Date, endDate: Date
|
|||||||
count(*) as total
|
count(*) as total
|
||||||
from event_data
|
from event_data
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_id = {{websiteId::uuid}}
|
||||||
and created_at >= {{dataStartDate}}
|
|
||||||
and created_at between {{startDate}} and {{endDate}}
|
and created_at between {{startDate}} and {{endDate}}
|
||||||
group by event_key, data_type
|
group by event_key, data_type
|
||||||
order by 3 desc, 2 asc, 1 asc
|
order by 3 desc, 2 asc, 1 asc
|
||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
{ websiteId, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,13 +68,12 @@ async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date
|
|||||||
from event_data
|
from event_data
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and event_key = {field:String}
|
and event_key = {field:String}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
group by event_key, string_value
|
group by event_key, string_value
|
||||||
order by 3 desc, 2 desc, 1 asc
|
order by 3 desc, 2 desc, 1 asc
|
||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
{ websiteId, field, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ websiteId, field, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +85,11 @@ async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date
|
|||||||
count(*) as total
|
count(*) as total
|
||||||
from event_data
|
from event_data
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
group by event_key, data_type
|
group by event_key, data_type
|
||||||
order by 3 desc, 2 asc, 1 asc
|
order by 3 desc, 2 asc, 1 asc
|
||||||
limit 100
|
limit 100
|
||||||
`,
|
`,
|
||||||
{ websiteId, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
|||||||
import { WebsiteEventMetric } from 'lib/types';
|
import { WebsiteEventMetric } from 'lib/types';
|
||||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getEventMetrics(
|
export async function getEventMetrics(
|
||||||
...args: [
|
...args: [
|
||||||
@ -57,7 +58,6 @@ async function relationalQuery(
|
|||||||
count(*) y
|
count(*) y
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_id = {{websiteId::uuid}}
|
||||||
and created_at >= {{dataStartDate}}
|
|
||||||
and created_at between {{startDate}} and {{endDate}}
|
and created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type = {{eventType}}
|
and event_type = {{eventType}}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
@ -67,9 +67,8 @@ async function relationalQuery(
|
|||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: EVENT_TYPE.customEvent,
|
eventType: EVENT_TYPE.customEvent,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -106,7 +105,6 @@ async function clickhouseQuery(
|
|||||||
count(*) y
|
count(*) y
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
and event_type = {eventType:UInt32}
|
and event_type = {eventType:UInt32}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
@ -116,9 +114,8 @@ async function clickhouseQuery(
|
|||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: EVENT_TYPE.customEvent,
|
eventType: EVENT_TYPE.customEvent,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
import clickhouse from 'lib/clickhouse';
|
import clickhouse from 'lib/clickhouse';
|
||||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
import { EVENT_TYPE } from 'lib/constants';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getPageviewMetrics(
|
export async function getPageviewMetrics(
|
||||||
...args: [
|
...args: [
|
||||||
@ -35,9 +36,8 @@ async function relationalQuery(
|
|||||||
const website = await loadWebsite(websiteId);
|
const website = await loadWebsite(websiteId);
|
||||||
const params: any = {
|
const params: any = {
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,7 +58,6 @@ async function relationalQuery(
|
|||||||
from website_event
|
from website_event
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at >= {{dataStartDate}}
|
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type = {{eventType}}
|
and event_type = {{eventType}}
|
||||||
${excludeDomain}
|
${excludeDomain}
|
||||||
@ -85,9 +84,8 @@ async function clickhouseQuery(
|
|||||||
const website = await loadWebsite(websiteId);
|
const website = await loadWebsite(websiteId);
|
||||||
const params = {
|
const params = {
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||||
domain: undefined,
|
domain: undefined,
|
||||||
};
|
};
|
||||||
@ -106,7 +104,6 @@ async function clickhouseQuery(
|
|||||||
select ${column} x, count(*) y
|
select ${column} x, count(*) y
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
and event_type = {eventType:UInt32}
|
and event_type = {eventType:UInt32}
|
||||||
${excludeDomain}
|
${excludeDomain}
|
||||||
|
@ -3,6 +3,7 @@ import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
|||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getPageviewStats(
|
export async function getPageviewStats(
|
||||||
...args: [
|
...args: [
|
||||||
@ -57,7 +58,6 @@ async function relationalQuery(
|
|||||||
from website_event
|
from website_event
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at >= {{dataStartDate}}
|
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type = {{eventType}}
|
and event_type = {{eventType}}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
@ -66,9 +66,8 @@ async function relationalQuery(
|
|||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: EVENT_TYPE.pageView,
|
eventType: EVENT_TYPE.pageView,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -109,7 +108,6 @@ async function clickhouseQuery(
|
|||||||
count(${count !== '*' ? 'distinct session_id' : count}) as y
|
count(${count !== '*' ? 'distinct session_id' : count}) as y
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
and event_type = {eventType:UInt32}
|
and event_type = {eventType:UInt32}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
@ -120,10 +118,9 @@ async function clickhouseQuery(
|
|||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
eventType: EVENT_TYPE.pageView,
|
eventType: EVENT_TYPE.pageView,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse';
|
|||||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getSessionMetrics(
|
export async function getSessionMetrics(
|
||||||
...args: [
|
...args: [
|
||||||
@ -35,14 +36,13 @@ async function relationalQuery(
|
|||||||
on website_event.website_id = website.website_id
|
on website_event.website_id = website.website_id
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website.website_id = {{websiteId::uuid}}
|
where website.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at >= {{dataStartDate}}
|
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
)
|
)
|
||||||
group by 1
|
group by 1
|
||||||
order by 2 desc
|
order by 2 desc
|
||||||
limit 100`,
|
limit 100`,
|
||||||
{ ...filters, websiteId, startDate, endDate, dataStartDate: website.dataStartDate },
|
{ ...filters, websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,6 @@ async function clickhouseQuery(
|
|||||||
${column} x, count(distinct session_id) y
|
${column} x, count(distinct session_id) y
|
||||||
from website_event as x
|
from website_event as x
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
and event_type = {eventType:UInt32}
|
and event_type = {eventType:UInt32}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
@ -72,9 +71,8 @@ async function clickhouseQuery(
|
|||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: EVENT_TYPE.pageView,
|
eventType: EVENT_TYPE.pageView,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse';
|
|||||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
||||||
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getWebsiteDateRange(...args: [websiteId: string]) {
|
export async function getWebsiteDateRange(...args: [websiteId: string]) {
|
||||||
return runQuery({
|
return runQuery({
|
||||||
@ -40,8 +41,8 @@ async function clickhouseQuery(websiteId: string) {
|
|||||||
max(created_at) as max
|
max(created_at) as max
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
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 { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||||
import { loadWebsite } from 'lib/query';
|
import { loadWebsite } from 'lib/query';
|
||||||
|
import { max } from 'date-fns';
|
||||||
|
|
||||||
export async function getWebsiteStats(
|
export async function getWebsiteStats(
|
||||||
...args: [
|
...args: [
|
||||||
@ -44,7 +45,6 @@ async function relationalQuery(
|
|||||||
${joinSession}
|
${joinSession}
|
||||||
where event_type = {{eventType}}
|
where event_type = {{eventType}}
|
||||||
and website.website_id = {{websiteId::uuid}}
|
and website.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at >= {{dataStartDate}}
|
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
@ -53,9 +53,8 @@ async function relationalQuery(
|
|||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: EVENT_TYPE.pageView,
|
eventType: EVENT_TYPE.pageView,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -86,7 +85,6 @@ async function clickhouseQuery(
|
|||||||
max(created_at) max_time
|
max(created_at) max_time
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at >= {dataStartDate:DateTime}
|
|
||||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||||
and event_type = {eventType:UInt32}
|
and event_type = {eventType:UInt32}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
@ -96,9 +94,8 @@ async function clickhouseQuery(
|
|||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate,
|
startDate: max([startDate, website.resetAt]),
|
||||||
endDate,
|
endDate,
|
||||||
dataStartDate: website.dataStartDate,
|
|
||||||
eventType: EVENT_TYPE.pageView,
|
eventType: EVENT_TYPE.pageView,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user