mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 23:27:12 +01:00
Initial Typescript models.
This commit is contained in:
parent
04e9f06e93
commit
0aaba8cbd1
74 changed files with 1144 additions and 768 deletions
56
queries/analytics/session/createSession.ts
Normal file
56
queries/analytics/session/createSession.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import kafka from 'lib/kafka';
|
||||
import prisma from 'lib/prisma';
|
||||
import cache from 'lib/cache';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
export async function createSession(args: Prisma.SessionCreateInput) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(args),
|
||||
}).then(async data => {
|
||||
if (cache.enabled) {
|
||||
await cache.storeSession(data);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(data: Prisma.SessionCreateInput) {
|
||||
return prisma.client.session.create({ data });
|
||||
}
|
||||
|
||||
async function clickhouseQuery(data: {
|
||||
id: string;
|
||||
websiteId: string;
|
||||
hostname?: string;
|
||||
browser?: string;
|
||||
os?: string;
|
||||
device?: string;
|
||||
screen?: string;
|
||||
language?: string;
|
||||
country?: string;
|
||||
}) {
|
||||
const { id, websiteId, hostname, browser, os, device, screen, language, country } = data;
|
||||
const { getDateFormat, sendMessage } = kafka;
|
||||
const website = await cache.fetchWebsite(websiteId);
|
||||
|
||||
const msg = {
|
||||
session_id: id,
|
||||
website_id: websiteId,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
rev_id: website?.revId || 0,
|
||||
created_at: getDateFormat(new Date()),
|
||||
};
|
||||
|
||||
await sendMessage(msg, 'event');
|
||||
|
||||
return data;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue