adding event tracker

This commit is contained in:
Emily
2024-06-11 18:41:45 +02:00
parent da6984add9
commit 7460ad5ed4
7 changed files with 146 additions and 12 deletions

View File

@@ -14,18 +14,9 @@ export default defineEventHandler(async event => {
const project = await getUserProjectFromId(project_id, user);
if (!project) return;
const names: string[] = await Redis.useCache({
key: `counts:${project_id}:event_names`,
exp: EVENT_NAMES_EXPIRE_TIME
}, async () => {
const namesAggregation = await EventModel.aggregate([
{ $match: { project_id: project._id } },
{ $group: { _id: "$name" } }
]);
const names: string[] = await Redis.useCache({ key: `event_names:${project_id}`, exp: EVENT_NAMES_EXPIRE_TIME }, async () => {
const namesAggregation = await EventModel.aggregate([{ $match: { project_id: project._id } }, { $group: { _id: "$name" } }]);
return namesAggregation.map(e => e._id);
});
return names;