remove session recalculate and related queries
This commit is contained in:
1 parent
eb9a77ea64
commit
58ee28a55e
5 files changed
+75
-72
No files matched your search
@@ -65,3 +65,4 @@ export * from './sessions/getWebsiteSessionStats';
|
||||
export * from './sessions/getWebsiteSessions';
|
||||
export * from './sessions/saveSessionData';
|
||||
export * from './sessions/saveSessionLink';
|
||||
export * from './sessions/updateSession';
|
||||
@@ -0,0 +1,49 @@
|
||||
import clickhouse from '@/lib/clickhouse';
|
||||
import { FIELD_LENGTH } from '@/lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||
import { truncateString } from '@/lib/format';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
const FUNCTION_NAME = 'updateSession';
|
||||
|
||||
export interface UpdateSessionArgs {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
distinctId: string;
|
||||
}
|
||||
|
||||
export async function updateSession(data: UpdateSessionArgs) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(data),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery({ websiteId, sessionId, distinctId }: UpdateSessionArgs) {
|
||||
const { writeRawQuery } = prisma;
|
||||
|
||||
await writeRawQuery(
|
||||
`
|
||||
update session
|
||||
set distinct_id = {{distinctId}}
|
||||
where website_id = {{websiteId}}
|
||||
and session_id = {{sessionId}}
|
||||
and coalesce(distinct_id, '') != {{distinctId}}
|
||||
`,
|
||||
{
|
||||
websiteId,
|
||||
sessionId,
|
||||
distinctId: truncateString(distinctId, FIELD_LENGTH.distinctId),
|
||||
},
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery() {
|
||||
if (!clickhouse.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ClickHouse session reads fall back to session_link because session rows are event-derived.
|
||||
return;
|
||||
}
|
||||
Reference in new issue
Block a user