improvements while testing
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
03cee826ff
commit
41e46570b7
@@ -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