mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 16:17:13 +01:00
Refactored queries.
This commit is contained in:
parent
f36a689817
commit
8904b7b4ed
27 changed files with 137 additions and 144 deletions
|
|
@ -2,7 +2,7 @@ import { Prisma } from '@prisma/client';
|
|||
import { DATA_TYPE } from 'lib/constants';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import { flattenJSON } from 'lib/dynamicData';
|
||||
import { flattenJSON } from 'lib/data';
|
||||
import kafka from 'lib/kafka';
|
||||
import prisma from 'lib/prisma';
|
||||
import { DynamicData } from 'lib/types';
|
||||
|
|
|
|||
|
|
@ -2,24 +2,23 @@ import prisma from 'lib/prisma';
|
|||
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 { EVENT_TYPE } from 'lib/constants';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
export interface GetEventMetricsCriteria {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
timezone: string;
|
||||
unit: string;
|
||||
filters: {
|
||||
url: string;
|
||||
eventName: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function getEventMetrics(
|
||||
...args: [
|
||||
websiteId: string,
|
||||
data: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
timezone: string;
|
||||
unit: string;
|
||||
filters: {
|
||||
url: string;
|
||||
eventName: string;
|
||||
};
|
||||
},
|
||||
]
|
||||
...args: [websiteId: string, criteria: GetEventMetricsCriteria]
|
||||
): Promise<WebsiteEventMetric[]> {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
|
|
@ -27,25 +26,8 @@ export async function getEventMetrics(
|
|||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
{
|
||||
startDate,
|
||||
endDate,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
filters,
|
||||
}: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
timezone: string;
|
||||
unit: string;
|
||||
filters: {
|
||||
url: string;
|
||||
eventName: string;
|
||||
};
|
||||
},
|
||||
) {
|
||||
async function relationalQuery(websiteId: string, criteria: GetEventMetricsCriteria) {
|
||||
const { startDate, endDate, timezone = 'utc', unit = 'day', filters } = criteria;
|
||||
const { rawQuery, getDateQuery, getFilterQuery } = prisma;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const filterQuery = getFilterQuery(filters);
|
||||
|
|
@ -74,25 +56,8 @@ async function relationalQuery(
|
|||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
{
|
||||
startDate,
|
||||
endDate,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
filters,
|
||||
}: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
timezone: string;
|
||||
unit: string;
|
||||
filters: {
|
||||
url: string;
|
||||
eventName: string;
|
||||
};
|
||||
},
|
||||
) {
|
||||
async function clickhouseQuery(websiteId: string, criteria: GetEventMetricsCriteria) {
|
||||
const { startDate, endDate, timezone = 'utc', unit = 'day', filters } = criteria;
|
||||
const { rawQuery, getDateQuery, getFilterQuery } = clickhouse;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const filterQuery = getFilterQuery(filters);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { Prisma } from '@prisma/client';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getSession(where: Prisma.SessionWhereUniqueInput) {
|
||||
export async function getSession(id: string) {
|
||||
return prisma.client.session.findUnique({
|
||||
where,
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { DATA_TYPE } from 'lib/constants';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { flattenJSON } from 'lib/dynamicData';
|
||||
import { flattenJSON } from 'lib/data';
|
||||
import prisma from 'lib/prisma';
|
||||
import { DynamicData } from 'lib/types';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue