mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
clickhouse inserts
This commit is contained in:
parent
6ea2282f82
commit
65910c7348
13 changed files with 146 additions and 40 deletions
|
|
@ -1,6 +1,21 @@
|
|||
import { prisma, runQuery } from 'lib/db';
|
||||
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
import {
|
||||
getDateFormatClickhouse,
|
||||
prisma,
|
||||
rawQueryClickhouse,
|
||||
runAnalyticsQuery,
|
||||
runQuery,
|
||||
} from 'lib/db';
|
||||
import { getSessionByUuid } from 'queries';
|
||||
|
||||
export async function createSession(website_id, data) {
|
||||
export async function createSession(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(website_id, data) {
|
||||
return runQuery(
|
||||
prisma.session.create({
|
||||
data: {
|
||||
|
|
@ -13,3 +28,28 @@ export async function createSession(website_id, data) {
|
|||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(
|
||||
website_id,
|
||||
{ session_uuid, hostname, browser, os, screen, language, country, device },
|
||||
) {
|
||||
const params = [
|
||||
session_uuid,
|
||||
website_id,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country ? country : null,
|
||||
];
|
||||
|
||||
await rawQueryClickhouse(
|
||||
`insert into umami_dev.session (created_at, session_uuid, website_id, hostname, browser, os, device, screen, language, country)
|
||||
values (${getDateFormatClickhouse(new Date())}, $1, $2, $3, $4, $5, $6, $7, $8, $9);`,
|
||||
params,
|
||||
);
|
||||
|
||||
return getSessionByUuid(session_uuid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ async function clickhouseQuery(session_uuid) {
|
|||
return rawQueryClickhouse(
|
||||
`
|
||||
select
|
||||
session_id,
|
||||
session_uuid,
|
||||
website_id,
|
||||
created_at,
|
||||
|
|
@ -36,7 +35,7 @@ async function clickhouseQuery(session_uuid) {
|
|||
"language",
|
||||
country
|
||||
from session
|
||||
where session_id = $1
|
||||
where session_uuid = $1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -40,14 +40,19 @@ async function relationalQuery(website_id, start_at, end_at, field, filters = {}
|
|||
|
||||
async function clickhouseQuery(website_id, start_at, end_at, field, filters = {}) {
|
||||
const params = [website_id];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(
|
||||
'pageview',
|
||||
filters,
|
||||
params,
|
||||
'session_uuid',
|
||||
);
|
||||
|
||||
return rawQueryClickhouse(
|
||||
`
|
||||
select ${field} x, count(*) y
|
||||
from session as x
|
||||
where x.session_id in (
|
||||
select pageview.session_id
|
||||
where x.session_uuid in (
|
||||
select pageview.session_uuid
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue