mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Compare commits
5 commits
5ded9abbfe
...
d382ad2975
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d382ad2975 | ||
|
|
b1dc690e2f | ||
|
|
cc8254985b | ||
|
|
a3f32b036d | ||
|
|
3cb7fa34b0 |
4 changed files with 32 additions and 27 deletions
|
|
@ -51,12 +51,12 @@ function getUTCString(date?: Date | string | number) {
|
|||
return formatInTimeZone(date || new Date(), 'UTC', 'yyyy-MM-dd HH:mm:ss');
|
||||
}
|
||||
|
||||
function getDateStringSQL(field: string, unit: string, timezone?: string) {
|
||||
function getDateStringSQL(data: any, unit: string = 'utc', timezone?: string) {
|
||||
if (timezone) {
|
||||
return `formatDateTime(${field}, '${CLICKHOUSE_DATE_FORMATS[unit]}', '${timezone}')`;
|
||||
return `formatDateTime(${data}, '${CLICKHOUSE_DATE_FORMATS[unit]}', '${timezone}')`;
|
||||
}
|
||||
|
||||
return `formatDateTime(${field}, '${CLICKHOUSE_DATE_FORMATS[unit]}')`;
|
||||
return `formatDateTime(${data}, '${CLICKHOUSE_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
|
||||
function getDateSQL(field: string, unit: string, timezone?: string) {
|
||||
|
|
|
|||
|
|
@ -135,26 +135,31 @@ export async function resetWebsite(websiteId: string) {
|
|||
const { client, transaction } = prisma;
|
||||
const cloudMode = !!process.env.CLOUD_MODE;
|
||||
|
||||
return transaction([
|
||||
client.eventData.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.sessionData.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.websiteEvent.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.session.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.website.update({
|
||||
where: { id: websiteId },
|
||||
data: {
|
||||
resetAt: new Date(),
|
||||
},
|
||||
}),
|
||||
]).then(async data => {
|
||||
return transaction(
|
||||
[
|
||||
client.eventData.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.sessionData.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.websiteEvent.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.session.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.website.update({
|
||||
where: { id: websiteId },
|
||||
data: {
|
||||
resetAt: new Date(),
|
||||
},
|
||||
}),
|
||||
],
|
||||
{
|
||||
timeout: 30000,
|
||||
},
|
||||
).then(async data => {
|
||||
if (cloudMode) {
|
||||
await redis.client.set(
|
||||
`website:${websiteId}`,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ async function relationalQuery(
|
|||
for (let i = 1; i <= steps; i++) {
|
||||
const endQuery = i < steps ? ',' : '';
|
||||
selectQuery += `s.e${i},`;
|
||||
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN event ELSE NULL END) AS e${i}${endQuery}`;
|
||||
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN "event" ELSE NULL END) AS e${i}${endQuery}`;
|
||||
groupByQuery += `s.e${i}${endQuery} `;
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ async function clickhouseQuery(
|
|||
for (let i = 1; i <= steps; i++) {
|
||||
const endQuery = i < steps ? ',' : '';
|
||||
selectQuery += `s.e${i},`;
|
||||
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN event ELSE NULL END) AS e${i}${endQuery}`;
|
||||
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN "event" ELSE NULL END) AS e${i}${endQuery}`;
|
||||
groupByQuery += `s.e${i}${endQuery} `;
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ async function clickhouseQuery(
|
|||
WITH events AS (
|
||||
select distinct
|
||||
visit_id,
|
||||
coalesce(nullIf(event_name, ''), url_path) event,
|
||||
coalesce(nullIf(event_name, ''), url_path) "event",
|
||||
row_number() OVER (PARTITION BY visit_id ORDER BY created_at) AS event_number
|
||||
from website_event
|
||||
${cohortQuery}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ async function clickhouseQuery(
|
|||
user_activities AS (
|
||||
select distinct
|
||||
website_event.session_id,
|
||||
(${getDateSQL('created_at', unit, timezone)} - cohort_items.cohort_date) / 86400 as day_number
|
||||
toInt32((${getDateSQL('created_at', unit, timezone)} - cohort_items.cohort_date) / 86400) as day_number
|
||||
from website_event
|
||||
join cohort_items
|
||||
on website_event.session_id = cohort_items.session_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue