mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
rewrite
This commit is contained in:
26
dashboard/server/api/data/events_data/names.ts
Normal file
26
dashboard/server/api/data/events_data/names.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
import { EventModel } from "@schema/metrics/EventSchema";
|
||||
import { Redis } from "~/server/services/CacheService";
|
||||
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestData(event, { requireSchema: false });
|
||||
if (!data) return;
|
||||
|
||||
const { project_id } = data;
|
||||
|
||||
const names: string[] = await Redis.useCache({
|
||||
key: `event_names:${project_id}`,
|
||||
exp: 60
|
||||
}, async () => {
|
||||
const namesAggregation = await EventModel.aggregate([
|
||||
{ $match: { project_id } },
|
||||
{ $group: { _id: "$name" } }
|
||||
]);
|
||||
return namesAggregation.map(e => e._id);
|
||||
});
|
||||
|
||||
return names;
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user