mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 16:17:13 +01:00
Merge branch 'dev' of https://github.com/umami-software/umami into feat/add-segments
This commit is contained in:
commit
a753809a74
5 changed files with 56 additions and 60 deletions
|
|
@ -24,7 +24,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
|
||||
return pagedRawQuery(
|
||||
`
|
||||
with events as (
|
||||
select
|
||||
event_id as "id",
|
||||
website_id as "websiteId",
|
||||
|
|
@ -49,8 +48,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
: ''
|
||||
}
|
||||
order by created_at desc
|
||||
limit 1000)
|
||||
select * from events
|
||||
`,
|
||||
{ ...params, search: `%${search}%` },
|
||||
pageParams,
|
||||
|
|
@ -64,7 +61,6 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
|
||||
return pagedQuery(
|
||||
`
|
||||
with events as (
|
||||
select
|
||||
event_id as id,
|
||||
website_id as websiteId,
|
||||
|
|
@ -89,8 +85,6 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
: ''
|
||||
}
|
||||
order by created_at desc
|
||||
limit 1000)
|
||||
select * from events
|
||||
`,
|
||||
{ ...params, search },
|
||||
pageParams,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import { Prisma } from '@prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export async function createSession(data: Prisma.SessionCreateInput) {
|
||||
export async function createSession(
|
||||
data: Prisma.SessionCreateInput,
|
||||
options = { skipDuplicates: false },
|
||||
) {
|
||||
const {
|
||||
id,
|
||||
websiteId,
|
||||
|
|
@ -16,19 +19,31 @@ export async function createSession(data: Prisma.SessionCreateInput) {
|
|||
distinctId,
|
||||
} = data;
|
||||
|
||||
return prisma.client.session.create({
|
||||
data: {
|
||||
id,
|
||||
websiteId,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
region,
|
||||
city,
|
||||
distinctId,
|
||||
},
|
||||
});
|
||||
try {
|
||||
return await prisma.client.session.create({
|
||||
data: {
|
||||
id,
|
||||
websiteId,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
region,
|
||||
city,
|
||||
distinctId,
|
||||
},
|
||||
});
|
||||
} catch (e: any) {
|
||||
// With skipDuplicates flag: ignore unique constraint error and return null
|
||||
if (
|
||||
options.skipDuplicates &&
|
||||
e instanceof Prisma.PrismaClientKnownRequestError &&
|
||||
e.code === 'P2002'
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
|
||||
return pagedRawQuery(
|
||||
`
|
||||
with sessions as (
|
||||
select
|
||||
session.session_id as "id",
|
||||
session.website_id as "websiteId",
|
||||
|
|
@ -68,8 +67,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
session.region,
|
||||
session.city
|
||||
order by max(website_event.created_at) desc
|
||||
limit 1000)
|
||||
select * from sessions
|
||||
`,
|
||||
{ ...params, search: `%${search}%` },
|
||||
pageParams,
|
||||
|
|
@ -83,7 +80,6 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
|
||||
return pagedQuery(
|
||||
`
|
||||
with sessions as (
|
||||
select
|
||||
session_id as id,
|
||||
website_id as websiteId,
|
||||
|
|
@ -116,8 +112,6 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
}
|
||||
group by session_id, website_id, hostname, browser, os, device, screen, language, country, region, city
|
||||
order by lastAt desc
|
||||
limit 1000)
|
||||
select * from sessions
|
||||
`,
|
||||
{ ...params, search },
|
||||
pageParams,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue