mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
fix collect
This commit is contained in:
parent
61df707765
commit
07d003e858
@ -61,7 +61,7 @@ function getDateFormat(date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCommaSeparatedStringFormat(data) {
|
function getCommaSeparatedStringFormat(data) {
|
||||||
return data.map(a => `'${a}'`).join(',');
|
return data.map(a => `'${a}'`).join(',') || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBetweenDates(field, start_at, end_at) {
|
function getBetweenDates(field, start_at, end_at) {
|
||||||
|
@ -39,7 +39,7 @@ export async function getSession(req) {
|
|||||||
// Check database if does not exists in Redis
|
// Check database if does not exists in Redis
|
||||||
if (!websiteId) {
|
if (!websiteId) {
|
||||||
const website = await getWebsiteByUuid(websiteUuid);
|
const website = await getWebsiteByUuid(websiteUuid);
|
||||||
websiteId = website ? website.websiteId : null;
|
websiteId = website ? website.id : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!websiteId || websiteId === DELETED) {
|
if (!websiteId || websiteId === DELETED) {
|
||||||
@ -47,7 +47,7 @@ export async function getSession(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
|
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
|
||||||
const sessionUuid = uuid(websiteId, hostname, ip, userAgent);
|
const sessionUuid = uuid(websiteUuid, hostname, ip, userAgent);
|
||||||
|
|
||||||
let sessionId = null;
|
let sessionId = null;
|
||||||
let session = null;
|
let session = null;
|
||||||
@ -61,7 +61,7 @@ export async function getSession(req) {
|
|||||||
// Check database if does not exists in Redis
|
// Check database if does not exists in Redis
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
session = await getSessionByUuid(sessionUuid);
|
session = await getSessionByUuid(sessionUuid);
|
||||||
sessionId = session ? session.sessionId : null;
|
sessionId = session ? session.id : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
@ -97,7 +97,10 @@ export async function getSession(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
websiteId: websiteId,
|
website: {
|
||||||
|
websiteId,
|
||||||
|
websiteUuid,
|
||||||
|
},
|
||||||
session,
|
session,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ export default async (req, res) => {
|
|||||||
await useSession(req, res);
|
await useSession(req, res);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
session: { websiteId, session },
|
session: { website, session },
|
||||||
} = req;
|
} = req;
|
||||||
|
|
||||||
const { type, payload } = getJsonBody(req);
|
const { type, payload } = getJsonBody(req);
|
||||||
@ -73,9 +73,9 @@ export default async (req, res) => {
|
|||||||
const eventUuid = uuid();
|
const eventUuid = uuid();
|
||||||
|
|
||||||
if (type === 'pageview') {
|
if (type === 'pageview') {
|
||||||
await savePageView(websiteId, { session, url, referrer });
|
await savePageView(website, { session, url, referrer });
|
||||||
} else if (type === 'event') {
|
} else if (type === 'event') {
|
||||||
await saveEvent(websiteId, {
|
await saveEvent(website, {
|
||||||
session,
|
session,
|
||||||
eventUuid,
|
eventUuid,
|
||||||
url,
|
url,
|
||||||
@ -87,7 +87,11 @@ export default async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const token = createToken(
|
const token = createToken(
|
||||||
{ websiteId, sessionId: session.sessionId, sessionUuid: session.sessionUuid },
|
{
|
||||||
|
websiteId: website.websiteUuid,
|
||||||
|
sessionId: session.sessionId,
|
||||||
|
sessionUuid: session.sessionUuid,
|
||||||
|
},
|
||||||
secret(),
|
secret(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ export default async (req, res) => {
|
|||||||
const { userId } = req.auth;
|
const { userId } = req.auth;
|
||||||
|
|
||||||
const websites = await getUserWebsites(userId);
|
const websites = await getUserWebsites(userId);
|
||||||
const ids = websites.map(({ id }) => id);
|
const ids = websites.map(({ websiteUuid }) => websiteUuid);
|
||||||
const token = createToken({ websites: ids }, secret());
|
const token = createToken({ websites: ids }, secret());
|
||||||
const data = await getRealtimeData(ids, subMinutes(new Date(), 30));
|
const data = await getRealtimeData(ids, subMinutes(new Date(), 30));
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ function relationalQuery(websites, start_at) {
|
|||||||
return prisma.client.event.findMany({
|
return prisma.client.event.findMany({
|
||||||
where: {
|
where: {
|
||||||
website: {
|
website: {
|
||||||
id: {
|
websiteUuid: {
|
||||||
in: websites,
|
in: websites,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -10,7 +10,10 @@ export async function saveEvent(...args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function relationalQuery(websiteId, { sessionId, url, eventName, eventData }) {
|
async function relationalQuery(
|
||||||
|
{ websiteId },
|
||||||
|
{ session: { id: sessionId }, url, eventName, eventData },
|
||||||
|
) {
|
||||||
const data = {
|
const data = {
|
||||||
websiteId,
|
websiteId,
|
||||||
sessionId,
|
sessionId,
|
||||||
@ -32,7 +35,7 @@ async function relationalQuery(websiteId, { sessionId, url, eventName, eventData
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function clickhouseQuery(
|
async function clickhouseQuery(
|
||||||
websiteId,
|
{ websiteUuid: websiteId },
|
||||||
{ session: { country, sessionUuid, ...sessionArgs }, eventUuid, url, eventName, eventData },
|
{ session: { country, sessionUuid, ...sessionArgs }, eventUuid, url, eventName, eventData },
|
||||||
) {
|
) {
|
||||||
const { getDateFormat, sendMessage } = kafka;
|
const { getDateFormat, sendMessage } = kafka;
|
||||||
|
@ -13,7 +13,7 @@ async function relationalQuery(websites, start_at) {
|
|||||||
return prisma.client.pageview.findMany({
|
return prisma.client.pageview.findMany({
|
||||||
where: {
|
where: {
|
||||||
website: {
|
website: {
|
||||||
id: {
|
websiteUuid: {
|
||||||
in: websites,
|
in: websites,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -25,9 +25,9 @@ async function relationalQuery(websites, start_at) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function clickhouseQuery(websites, start_at) {
|
async function clickhouseQuery(websites, start_at) {
|
||||||
const { getCommaSeparatedStringFormat } = clickhouse;
|
const { rawQuery, getCommaSeparatedStringFormat } = clickhouse;
|
||||||
|
|
||||||
return clickhouse.rawQuery(
|
return rawQuery(
|
||||||
`select
|
`select
|
||||||
website_id,
|
website_id,
|
||||||
session_id,
|
session_id,
|
||||||
|
@ -10,7 +10,7 @@ export async function savePageView(...args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function relationalQuery(websiteId, { session: { sessionId }, url, referrer }) {
|
async function relationalQuery({ websiteId }, { session: { id: sessionId }, url, referrer }) {
|
||||||
return prisma.client.pageview.create({
|
return prisma.client.pageview.create({
|
||||||
data: {
|
data: {
|
||||||
websiteId,
|
websiteId,
|
||||||
@ -22,7 +22,7 @@ async function relationalQuery(websiteId, { session: { sessionId }, url, referre
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function clickhouseQuery(
|
async function clickhouseQuery(
|
||||||
websiteId,
|
{ websiteUuid: websiteId },
|
||||||
{ session: { country, sessionUuid, ...sessionArgs }, url, referrer },
|
{ session: { country, sessionUuid, ...sessionArgs }, url, referrer },
|
||||||
) {
|
) {
|
||||||
const { getDateFormat, sendMessage } = kafka;
|
const { getDateFormat, sendMessage } = kafka;
|
||||||
|
@ -18,7 +18,7 @@ async function relationalQuery(websiteId, data) {
|
|||||||
...data,
|
...data,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
sessionId: true,
|
id: true,
|
||||||
sessionUuid: true,
|
sessionUuid: true,
|
||||||
hostname: true,
|
hostname: true,
|
||||||
browser: true,
|
browser: true,
|
||||||
@ -31,7 +31,7 @@ async function relationalQuery(websiteId, data) {
|
|||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (redis.client && res) {
|
if (redis.client && res) {
|
||||||
await redis.client.set(`session:${res.sessionUuid}`, res.id);
|
await redis.client.set(`session:${res.sessionUuid}`, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -19,7 +19,7 @@ async function relationalQuery(sessionUuid) {
|
|||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (redis.client && res) {
|
if (redis.client && res) {
|
||||||
await redis.client.set(`session:${res.sessionUuid}`, res.sessionId);
|
await redis.client.set(`session:${res.sessionUuid}`, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -32,7 +32,7 @@ async function clickhouseQuery(sessionUuid) {
|
|||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`select distinct
|
`select distinct
|
||||||
session_uuid,
|
session_id,
|
||||||
website_id,
|
website_id,
|
||||||
created_at,
|
created_at,
|
||||||
hostname,
|
hostname,
|
||||||
@ -43,7 +43,7 @@ async function clickhouseQuery(sessionUuid) {
|
|||||||
language,
|
language,
|
||||||
country
|
country
|
||||||
from event
|
from event
|
||||||
where session_uuid = $1`,
|
where session_id = $1`,
|
||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
.then(result => findFirst(result))
|
.then(result => findFirst(result))
|
||||||
|
@ -15,7 +15,7 @@ async function relationalQuery(websites, start_at) {
|
|||||||
...(websites && websites.length > 0
|
...(websites && websites.length > 0
|
||||||
? {
|
? {
|
||||||
website: {
|
website: {
|
||||||
id: {
|
websiteUuid: {
|
||||||
in: websites,
|
in: websites,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -29,11 +29,11 @@ async function relationalQuery(websites, start_at) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function clickhouseQuery(websites, start_at) {
|
async function clickhouseQuery(websites, start_at) {
|
||||||
const { rawQuery, getDateFormat } = clickhouse;
|
const { rawQuery, getDateFormat, getCommaSeparatedStringFormat } = clickhouse;
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`select distinct
|
`select distinct
|
||||||
session_uuid,
|
session_id,
|
||||||
website_id,
|
website_id,
|
||||||
created_at,
|
created_at,
|
||||||
hostname,
|
hostname,
|
||||||
@ -44,7 +44,11 @@ async function clickhouseQuery(websites, start_at) {
|
|||||||
language,
|
language,
|
||||||
country
|
country
|
||||||
from event
|
from event
|
||||||
where ${websites && websites.length > 0 ? `website_id in (${websites.join(',')})` : '0 = 0'}
|
where ${
|
||||||
|
websites && websites.length > 0
|
||||||
|
? `website_id in (${getCommaSeparatedStringFormat(websites)})`
|
||||||
|
: '0 = 0'
|
||||||
|
}
|
||||||
and created_at >= ${getDateFormat(start_at)}`,
|
and created_at >= ${getDateFormat(start_at)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user