feat(root): added migrations and optimized profile table

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-10 10:08:26 +02:00
committed by Carl-Gerhard Lindesvärd
parent 2258fed24a
commit b44f1958a2
22 changed files with 280 additions and 169 deletions

View File

@@ -225,23 +225,24 @@ export async function getEvents(
options: GetEventsOptions = {}
): Promise<IServiceEvent[]> {
const events = await chQuery<IClickhouseEvent>(sql);
if (options.profile) {
const projectId = events[0]?.project_id;
if (options.profile && projectId) {
const ids = events.map((e) => e.profile_id);
const profiles = await getProfiles(ids);
const profiles = await getProfiles(ids, projectId);
for (const event of events) {
event.profile = profiles.find((p) => p.id === event.profile_id);
}
}
if (options.meta) {
if (options.meta && projectId) {
const names = uniq(events.map((e) => e.name));
const metas = await db.eventMeta.findMany({
where: {
name: {
in: names,
},
projectId: events[0]?.project_id,
projectId,
},
select: options.meta === true ? undefined : options.meta,
});