mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 23:57:12 +01:00
Added parseDateRangeQuery function.
This commit is contained in:
parent
a0aaeeeb57
commit
09af33c77e
15 changed files with 139 additions and 98 deletions
|
|
@ -2,9 +2,8 @@ import prisma from 'lib/prisma';
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import { WebsiteEventDataFields } from 'lib/types';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
||||
import { max } from 'date-fns';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getEventDataEvents(
|
||||
...args: [
|
||||
|
|
@ -48,7 +47,7 @@ async function relationalQuery(
|
|||
group by ed.event_key, ed.string_value
|
||||
order by 3 desc, 2 desc, 1 asc
|
||||
`,
|
||||
{ ...filters, websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ ...filters, websiteId, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
return rawQuery(
|
||||
|
|
@ -67,7 +66,7 @@ async function relationalQuery(
|
|||
group by we.event_name, ed.event_key, ed.string_value
|
||||
order by 3 desc, 2 desc, 1 asc
|
||||
`,
|
||||
{ websiteId, field, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ websiteId, field, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +97,7 @@ async function clickhouseQuery(
|
|||
order by 1 asc, 2 asc, 3 asc, 4 desc
|
||||
limit 100
|
||||
`,
|
||||
{ ...filters, websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ ...filters, websiteId, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +115,6 @@ async function clickhouseQuery(
|
|||
order by 1 asc, 2 asc
|
||||
limit 100
|
||||
`,
|
||||
{ websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ websiteId, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import prisma from 'lib/prisma';
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import { WebsiteEventDataFields } from 'lib/types';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { max } from 'date-fns';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getEventDataFields(
|
||||
...args: [websiteId: string, startDate: Date, endDate: Date, field?: string]
|
||||
|
|
@ -33,7 +33,7 @@ async function relationalQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
order by 3 desc, 2 desc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
{ websiteId, field, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ websiteId, field, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ async function relationalQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
order by 3 desc, 2 asc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
{ websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ websiteId, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
order by 3 desc, 2 desc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
{ websiteId, field, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ websiteId, field, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -90,6 +90,6 @@ async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
order by 3 desc, 2 asc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
{ websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ websiteId, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import clickhouse from 'lib/clickhouse';
|
|||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
import { WebsiteEventMetric } from 'lib/types';
|
||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { max } from 'date-fns';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getEventMetrics(
|
||||
...args: [
|
||||
|
|
@ -67,7 +67,7 @@ async function relationalQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.customEvent,
|
||||
},
|
||||
|
|
@ -114,7 +114,7 @@ async function clickhouseQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.customEvent,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import prisma from 'lib/prisma';
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
import { EVENT_TYPE } from 'lib/constants';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { max } from 'date-fns';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getPageviewMetrics(
|
||||
...args: [
|
||||
|
|
@ -36,7 +36,7 @@ async function relationalQuery(
|
|||
const website = await loadWebsite(websiteId);
|
||||
const params: any = {
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
};
|
||||
|
|
@ -84,7 +84,7 @@ async function clickhouseQuery(
|
|||
const website = await loadWebsite(websiteId);
|
||||
const params = {
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
domain: undefined,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import clickhouse from 'lib/clickhouse';
|
|||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { max } from 'date-fns';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getPageviewStats(
|
||||
...args: [
|
||||
|
|
@ -66,7 +66,7 @@ async function relationalQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
|
|
@ -118,7 +118,7 @@ async function clickhouseQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import prisma from 'lib/prisma';
|
|||
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';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getSessionMetrics(
|
||||
...args: [
|
||||
|
|
@ -42,7 +42,7 @@ async function relationalQuery(
|
|||
group by 1
|
||||
order by 2 desc
|
||||
limit 100`,
|
||||
{ ...filters, websiteId, startDate: max([startDate, website.resetAt]), endDate },
|
||||
{ ...filters, websiteId, startDate: maxDate(startDate, website.resetAt), endDate },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ async function clickhouseQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { DEFAULT_RESET_DATE } from 'lib/constants';
|
||||
import { max } from 'date-fns';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getWebsiteDateRange(...args: [websiteId: string]) {
|
||||
return runQuery({
|
||||
|
|
@ -43,6 +43,6 @@ async function clickhouseQuery(websiteId: string) {
|
|||
where website_id = {websiteId:UUID}
|
||||
and created_at >= {startDate:DateTime}
|
||||
`,
|
||||
{ websiteId, startDate: max([new Date('2000-01-01'), website.resetAt]) },
|
||||
{ websiteId, startDate: maxDate(new Date(DEFAULT_RESET_DATE), website.resetAt) },
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import prisma from 'lib/prisma';
|
||||
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';
|
||||
import { EVENT_TYPE } from 'lib/constants';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export async function getWebsiteStats(
|
||||
...args: [
|
||||
|
|
@ -53,7 +53,7 @@ async function relationalQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
|
|
@ -94,7 +94,7 @@ async function clickhouseQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: max([startDate, website.resetAt]),
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue