mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 09:45:04 +01:00
Merge pull request #1343 from umami-software/brian/session-fix
fix collection bug
This commit is contained in:
commit
d755a7fa24
12
lib/db.js
12
lib/db.js
@ -277,14 +277,22 @@ export async function rawQueryClickhouse(query, params = [], debug = false) {
|
||||
return clickhouse.query(formattedQuery).toPromise();
|
||||
}
|
||||
|
||||
export async function findUnique(data) {
|
||||
if (data.length > 1) {
|
||||
throw `${data.length} records found when expecting 1.`;
|
||||
}
|
||||
|
||||
return data[0] ?? null;
|
||||
}
|
||||
|
||||
export async function runAnalyticsQuery(queries) {
|
||||
const db = getAnalyticsDatabase();
|
||||
|
||||
if (db === POSTGRESQL || db === MYSQL) {
|
||||
return queries[`${RELATIONAL}`]();
|
||||
return queries[RELATIONAL]();
|
||||
}
|
||||
|
||||
if (db === CLICKHOUSE) {
|
||||
return queries[`${CLICKHOUSE}`]();
|
||||
return queries[CLICKHOUSE]();
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,6 @@ export async function getSession(req) {
|
||||
|
||||
let session = await getSessionByUuid(session_uuid);
|
||||
|
||||
session = Array.isArray(session) && session[0] ? session[0] : session;
|
||||
|
||||
if (!session) {
|
||||
try {
|
||||
session = await createSession(website_id, {
|
||||
|
@ -11,8 +11,8 @@ import {
|
||||
|
||||
export async function getEventMetrics(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ import {
|
||||
|
||||
export function getEvents(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ import {
|
||||
|
||||
export async function saveEvent(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ import {
|
||||
|
||||
export async function getPageviewMetrics(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ import { MYSQL, POSTGRESQL, CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
|
||||
export async function getPageviewParams(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,8 @@ import {
|
||||
|
||||
export async function getPageviewStats(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ import {
|
||||
|
||||
export async function getPageviews(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ import {
|
||||
|
||||
export async function savePageView(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ import { getSessionByUuid } from 'queries';
|
||||
|
||||
export async function createSession(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
import { rawQueryClickhouse, prisma, runAnalyticsQuery, runQuery } from 'lib/db';
|
||||
import { rawQueryClickhouse, findUnique, prisma, runAnalyticsQuery, runQuery } from 'lib/db';
|
||||
|
||||
export async function getSessionByUuid(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
@ -38,5 +38,5 @@ async function clickhouseQuery(session_uuid) {
|
||||
where session_uuid = $1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
).then(data => findUnique(data));
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ import {
|
||||
|
||||
export async function getSessionMetrics(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ import {
|
||||
|
||||
export async function getSessions(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,8 @@ import { getDateFormatClickhouse, rawQuery, rawQueryClickhouse, runAnalyticsQuer
|
||||
|
||||
export async function getActiveVisitors(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,8 @@ import {
|
||||
|
||||
export async function getWebsiteStats(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user