improve event list a bit

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-08-12 22:34:44 +02:00
parent c34c2cb93b
commit 64d3a59722
2 changed files with 18 additions and 3 deletions

View File

@@ -343,12 +343,25 @@ export async function getEventList({
sb.offset = Math.max(0, (cursor ?? 0) * take);
sb.where.projectId = `project_id = ${escape(projectId)}`;
// sb.select.id = 'id';
// sb.select.name = 'name';
// sb.select.deviceId = 'device_id';
// sb.select.profileId = 'profile_id';
// sb.select.projectId = 'project_id';
// sb.select.createdAt = 'created_at';
// sb.select.path = 'path';
// sb.select.duration = 'duration';
// sb.select.city = 'city';
// sb.select.country = 'country';
// sb.select.os = 'os';
// sb.select.browser = 'browser';
if (profileId) {
sb.where.deviceId = `device_id IN (SELECT device_id as did FROM ${TABLE_NAMES.events} WHERE profile_id = ${escape(profileId)} group by did)`;
}
if (startDate && endDate) {
sb.where.created_at = `created_at BETWEEN '${formatClickhouseDate(startDate)}' AND '${formatClickhouseDate(endDate)}'`;
sb.where.created_at = `toDate(created_at) BETWEEN '${formatClickhouseDate(startDate)}' AND '${formatClickhouseDate(endDate)}'`;
}
if (events && events.length > 0) {
@@ -369,7 +382,8 @@ export async function getEventList({
// sb.where.cursor = `created_at <= '${formatClickhouseDate(cursor)}'`;
// }
sb.orderBy.created_at = 'created_at DESC';
sb.orderBy.created_at =
'toDate(created_at) DESC, created_at DESC, profile_id DESC, name DESC';
return getEvents(getSql(), { profile, meta });
}

View File

@@ -1,3 +1,4 @@
import { uniq } from 'ramda';
import { escape } from 'sqlstring';
import { toObject } from '@openpanel/common';
@@ -66,7 +67,7 @@ interface GetProfileListOptions {
}
export async function getProfiles(ids: string[]) {
const filteredIds = ids.filter((id) => id !== '');
const filteredIds = uniq(ids.filter((id) => id !== ''));
if (filteredIds.length === 0) {
return [];