mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 20:45:39 +01:00
Add collect limits.
This commit is contained in:
parent
f42cab8d83
commit
e487da72c3
13 changed files with 217 additions and 61 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { Prisma, Session } from '@prisma/client';
|
||||
|
||||
export async function getSession(args: { id: string }) {
|
||||
return runQuery({
|
||||
|
|
@ -10,7 +10,7 @@ export async function getSession(args: { id: string }) {
|
|||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(where: Prisma.SessionWhereUniqueInput) {
|
||||
async function relationalQuery(where: Prisma.SessionWhereUniqueInput): Promise<Session> {
|
||||
return prisma.client.session.findUnique({
|
||||
where,
|
||||
});
|
||||
|
|
|
|||
38
queries/analytics/stats/getViewTotals.ts
Normal file
38
queries/analytics/stats/getViewTotals.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getViewTotals(...args: [websites: string[], startDate: Date]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websites: string[], startDate: Date) {
|
||||
return prisma.client.websiteEvent.count({
|
||||
where: {
|
||||
websiteId: {
|
||||
in: websites,
|
||||
},
|
||||
createdAt: {
|
||||
gte: startDate,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteIds: string[], startDate: Date) {
|
||||
const { rawQuery, getDateFormat, getCommaSeparatedStringFormat, findFirst } = clickhouse;
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
count(*) as views
|
||||
from event
|
||||
where
|
||||
website_id in (${getCommaSeparatedStringFormat(websiteIds)})
|
||||
and created_at >= ${getDateFormat(startDate)}
|
||||
`,
|
||||
).then(data => findFirst(data));
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ async function relationalQuery(
|
|||
) {
|
||||
const { startDate, endDate, filters = {} } = data;
|
||||
const { getDateQuery, getTimestampInterval, parseFilters, rawQuery } = prisma;
|
||||
const params = [startDate, endDate];
|
||||
const params: any = [startDate, endDate];
|
||||
const { filterQuery, joinSession } = parseFilters(filters, params);
|
||||
|
||||
return rawQuery(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue