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