mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 16:45:35 +01:00
Database refactoring.
This commit is contained in:
parent
bb184dc2cc
commit
467c7f289f
37 changed files with 566 additions and 591 deletions
|
|
@ -1,54 +1,52 @@
|
|||
import { CLICKHOUSE, KAFKA, RELATIONAL, URL_LENGTH } from 'lib/constants';
|
||||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runAnalyticsQuery } from 'lib/db';
|
||||
import kafka from 'lib/kafka';
|
||||
import { prisma, runQuery } from 'lib/relational';
|
||||
import { runQuery, CLICKHOUSE, KAFKA, PRISMA } from 'lib/db';
|
||||
import { URL_LENGTH } from 'lib/constants';
|
||||
|
||||
export async function savePageView(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
[KAFKA]: () => kafkaQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(website_id, { session_id, url, referrer }) {
|
||||
return runQuery(
|
||||
prisma.pageview.create({
|
||||
data: {
|
||||
website_id,
|
||||
session_id,
|
||||
url: url?.substr(0, URL_LENGTH),
|
||||
referrer: referrer?.substr(0, URL_LENGTH),
|
||||
},
|
||||
}),
|
||||
);
|
||||
return prisma.client.pageview.create({
|
||||
data: {
|
||||
website_id,
|
||||
session_id,
|
||||
url: url?.substring(0, URL_LENGTH),
|
||||
referrer: referrer?.substring(0, URL_LENGTH),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(website_id, { session_uuid, url, referrer }) {
|
||||
const params = [
|
||||
website_id,
|
||||
session_uuid,
|
||||
url?.substr(0, URL_LENGTH),
|
||||
referrer?.substr(0, URL_LENGTH),
|
||||
url?.substring(0, URL_LENGTH),
|
||||
referrer?.substring(0, URL_LENGTH),
|
||||
];
|
||||
|
||||
return clickhouse.rawQuery(
|
||||
`
|
||||
insert into umami.pageview (created_at, website_id, session_uuid, url, referrer)
|
||||
`insert into umami.pageview (created_at, website_id, session_uuid, url, referrer)
|
||||
values (${clickhouse.getDateFormat(new Date())}, $1, $2, $3, $4);`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
async function kafkaQuery(website_id, { session_uuid, url, referrer }) {
|
||||
const { getDateFormat, sendMessage } = kafka;
|
||||
const params = {
|
||||
website_id: website_id,
|
||||
session_uuid: session_uuid,
|
||||
created_at: kafka.getDateFormat(new Date()),
|
||||
url: url?.substr(0, URL_LENGTH),
|
||||
referrer: referrer?.substr(0, URL_LENGTH),
|
||||
created_at: getDateFormat(new Date()),
|
||||
url: url?.substring(0, URL_LENGTH),
|
||||
referrer: referrer?.substring(0, URL_LENGTH),
|
||||
};
|
||||
|
||||
await kafka.sendMessage(params, 'pageview');
|
||||
await sendMessage(params, 'pageview');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue