mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
change in progress
This commit is contained in:
35
dashboard/server/api/timeline/sessions_duration.ts
Normal file
35
dashboard/server/api/timeline/sessions_duration.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { SessionModel } from "@schema/metrics/SessionSchema";
|
||||
import { Redis } from "~/server/services/CacheService";
|
||||
import { executeAdvancedTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestData(event, { requireSchema: false, requireSlice: true });
|
||||
if (!data) return;
|
||||
|
||||
const { pid, from, to, slice, project_id } = data;
|
||||
|
||||
const cacheKey = `timeline:sessions_duration:${pid}:${from}:${to}`;
|
||||
const cacheExp = 60;
|
||||
|
||||
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
|
||||
const timelineData = await executeAdvancedTimelineAggregation({
|
||||
projectId: project_id,
|
||||
model: SessionModel,
|
||||
from, to, slice,
|
||||
customGroup: {
|
||||
duration: { $sum: '$duration' }
|
||||
},
|
||||
customProjection: {
|
||||
count: { $divide: ["$duration", "$count"] }
|
||||
},
|
||||
});
|
||||
const timelineFilledMerged = fillAndMergeTimelineAggregationV2(timelineData, slice, from, to);
|
||||
return timelineFilledMerged;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user