improvements while testing
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
03cee826ff
commit
41e46570b7
@@ -60,6 +60,15 @@ CREATE TABLE IF NOT EXISTS openpanel.profiles (
|
||||
ORDER BY
|
||||
(id) SETTINGS index_granularity = 8192;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS openpanel.profile_aliases (
|
||||
`project_id` String,
|
||||
`profile_id` String,
|
||||
`alias` String,
|
||||
`created_at` DateTime
|
||||
) ENGINE = MergeTree
|
||||
ORDER BY
|
||||
(project_id, profile_id, alias) SETTINGS index_granularity = 8192;
|
||||
|
||||
--- Materialized views (DAU)
|
||||
CREATE MATERIALIZED VIEW IF NOT EXISTS dau_mv ENGINE = AggregatingMergeTree() PARTITION BY toYYYYMMDD(date)
|
||||
ORDER BY
|
||||
|
||||
@@ -111,10 +111,13 @@ export async function chQuery<T extends Record<string, any>>(
|
||||
return (await chQueryWithMeta<T>(query)).data;
|
||||
}
|
||||
|
||||
export function formatClickhouseDate(_date: Date | string, skipTime = false) {
|
||||
export function formatClickhouseDate(
|
||||
_date: Date | string,
|
||||
skipTime = false
|
||||
): string {
|
||||
const date = typeof _date === 'string' ? new Date(_date) : _date;
|
||||
if (skipTime) {
|
||||
return date.toISOString().split('T')[0];
|
||||
return date.toISOString().split('T')[0]!;
|
||||
}
|
||||
return date.toISOString().replace('T', ' ').replace(/Z+$/, '');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { escape } from 'sqlstring';
|
||||
|
||||
import { toObject } from '@openpanel/common';
|
||||
import { cacheable } from '@openpanel/redis';
|
||||
import type { IChartEventFilter } from '@openpanel/validation';
|
||||
|
||||
import { profileBuffer } from '../buffers';
|
||||
@@ -191,3 +192,31 @@ export async function upsertProfile({
|
||||
is_external: isExternal,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getProfileId({
|
||||
profileId,
|
||||
projectId,
|
||||
}: {
|
||||
profileId: string | undefined;
|
||||
projectId: string;
|
||||
}) {
|
||||
if (!profileId) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const res = await chQuery<{
|
||||
alias: string;
|
||||
profile_id: string;
|
||||
project_id: string;
|
||||
}>(
|
||||
`SELECT * FROM ${TABLE_NAMES.alias} WHERE project_id = '${projectId}' AND (alias = '${profileId}' OR profile_id = '${profileId}')`
|
||||
);
|
||||
|
||||
if (res[0]) {
|
||||
return res[0].profile_id;
|
||||
}
|
||||
|
||||
return profileId;
|
||||
}
|
||||
|
||||
export const getProfileIdCached = cacheable(getProfileId, 60 * 30);
|
||||
|
||||
Reference in New Issue
Block a user