mirror of
https://github.com/umami-software/umami.git
synced 2026-02-21 04:55:36 +01:00
Finish event_data relational.
This commit is contained in:
parent
f1f602b42d
commit
2343949d3e
12 changed files with 133 additions and 122 deletions
|
|
@ -40,11 +40,13 @@ async function relationalQuery(data: {
|
|||
eventName?: string;
|
||||
eventData?: any;
|
||||
}) {
|
||||
const { websiteId, id: sessionId, urlPath, urlQuery, eventName, pageTitle } = data;
|
||||
const { websiteId, id: sessionId, urlPath, urlQuery, eventName, eventData, pageTitle } = data;
|
||||
const website = await cache.fetchWebsite(websiteId);
|
||||
const websiteEventId = uuid();
|
||||
|
||||
return prisma.client.websiteEvent.create({
|
||||
const websiteEvent = prisma.client.websiteEvent.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
id: websiteEventId,
|
||||
websiteId,
|
||||
sessionId,
|
||||
urlPath: urlPath?.substring(0, URL_LENGTH),
|
||||
|
|
@ -54,6 +56,20 @@ async function relationalQuery(data: {
|
|||
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
|
||||
},
|
||||
});
|
||||
|
||||
if (eventData) {
|
||||
await saveEventData({
|
||||
websiteId,
|
||||
sessionId,
|
||||
eventId: websiteEventId,
|
||||
revId: website?.revId,
|
||||
urlPath: urlPath?.substring(0, URL_LENGTH),
|
||||
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
|
||||
eventData,
|
||||
});
|
||||
}
|
||||
|
||||
return websiteEvent;
|
||||
}
|
||||
|
||||
async function clickhouseQuery(data: {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ async function relationalQuery(
|
|||
) {
|
||||
const { startDate, endDate, timeSeries, eventName, urlPath, filters } = data;
|
||||
const { toUuid, rawQuery, getEventDataFilterQuery, getDateQuery } = prisma;
|
||||
const params: any = [websiteId, startDate, endDate, eventName];
|
||||
const params: any = [websiteId, startDate, endDate, eventName || ''];
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
|
|
@ -59,6 +59,11 @@ async function relationalQuery(
|
|||
timeSeries ? `,${getDateQuery('created_at', timeSeries.unit, timeSeries.timezone)} t` : ''
|
||||
}
|
||||
from event_data
|
||||
${
|
||||
eventName || urlPath
|
||||
? 'join website_event on event_data.id = website_event.website_event_id'
|
||||
: ''
|
||||
}
|
||||
where website_id = $1${toUuid()}
|
||||
and created_at between $2 and $3
|
||||
${eventName ? `and eventName = $4` : ''}
|
||||
|
|
@ -1,18 +1,21 @@
|
|||
import { Prisma } from '@prisma/client';
|
||||
import { EVENT_DATA_TYPE } from 'lib/constants';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import { flattenJSON } from 'lib/eventData';
|
||||
import kafka from 'lib/kafka';
|
||||
import prisma from 'lib/prisma';
|
||||
import { EventData } from 'lib/types';
|
||||
|
||||
export async function saveEventData(args: {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
revId: number;
|
||||
urlPath: string;
|
||||
eventName: string;
|
||||
sessionId?: string;
|
||||
revId?: number;
|
||||
urlPath?: string;
|
||||
eventName?: string;
|
||||
eventData: EventData;
|
||||
createdAt: string;
|
||||
createdAt?: string;
|
||||
}) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(args),
|
||||
|
|
@ -22,25 +25,44 @@ export async function saveEventData(args: {
|
|||
|
||||
async function relationalQuery(data: {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
revId: number;
|
||||
eventName: string;
|
||||
eventData: EventData;
|
||||
createdAt: string;
|
||||
}) {
|
||||
return data;
|
||||
}): Promise<Prisma.BatchPayload> {
|
||||
const { websiteId, eventId, eventData } = data;
|
||||
|
||||
const jsonKeys = flattenJSON(eventData);
|
||||
|
||||
//id, websiteEventId, eventStringValue
|
||||
const flattendData = jsonKeys.map(a => ({
|
||||
id: uuid(),
|
||||
websiteEventId: eventId,
|
||||
websiteId,
|
||||
eventKey: a.key,
|
||||
eventStringValue:
|
||||
a.eventDataType === EVENT_DATA_TYPE.string ||
|
||||
a.eventDataType === EVENT_DATA_TYPE.boolean ||
|
||||
a.eventDataType === EVENT_DATA_TYPE.array
|
||||
? a.value
|
||||
: null,
|
||||
eventNumericValue: a.eventDataType === EVENT_DATA_TYPE.number ? a.value : null,
|
||||
eventDateValue: a.eventDataType === EVENT_DATA_TYPE.date ? new Date(a.value) : null,
|
||||
eventDataType: a.eventDataType,
|
||||
}));
|
||||
|
||||
return prisma.client.eventData.createMany({
|
||||
data: flattendData,
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(data: {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
revId: number;
|
||||
urlPath: string;
|
||||
eventName: string;
|
||||
sessionId?: string;
|
||||
revId?: number;
|
||||
urlPath?: string;
|
||||
eventName?: string;
|
||||
eventData: EventData;
|
||||
createdAt: string;
|
||||
createdAt?: string;
|
||||
}) {
|
||||
const { websiteId, sessionId, eventId, revId, urlPath, eventName, eventData, createdAt } = data;
|
||||
|
||||
|
|
@ -67,7 +89,6 @@ async function clickhouseQuery(data: {
|
|||
event_data_type: a.eventDataType,
|
||||
created_at: createdAt,
|
||||
}));
|
||||
``;
|
||||
|
||||
await sendMessages(messages, 'event_data');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue