mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
aggregation optimization
This commit is contained in:
@@ -4,6 +4,7 @@ import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import DateService from "@services/DateService";
|
||||
import { executeTimelineAggregation, fillAndMergeTimelineAggregation } from "~/server/services/TimelineService";
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const project_id = getRequestProjectId(event);
|
||||
@@ -20,19 +21,24 @@ export default defineEventHandler(async event => {
|
||||
if (!to) return setResponseStatus(event, 400, 'to is required');
|
||||
if (!slice) return setResponseStatus(event, 400, 'slice is required');
|
||||
|
||||
return await Redis.useCache({
|
||||
key: `timeline:visits:${project_id}:${slice}:${from || 'none'}:${to || 'none'}`,
|
||||
exp: TIMELINE_EXPIRE_TIME
|
||||
}, async () => {
|
||||
const timelineData = await executeTimelineAggregation({
|
||||
projectId: project._id,
|
||||
model: VisitModel,
|
||||
from, to, slice
|
||||
});
|
||||
const timelineFilledMerged = fillAndMergeTimelineAggregation(timelineData, slice);
|
||||
return timelineFilledMerged;
|
||||
// return await Redis.useCache({
|
||||
// key: `timeline:visits:${project_id}:${slice}:${from || 'none'}:${to || 'none'}`,
|
||||
// exp: TIMELINE_EXPIRE_TIME,
|
||||
// }, async () => {
|
||||
const timelineData = await executeTimelineAggregation({
|
||||
projectId: project._id,
|
||||
model: VisitModel,
|
||||
from, to, slice,
|
||||
debug: true
|
||||
});
|
||||
|
||||
console.log(timelineData);
|
||||
fs.writeFileSync('explains/timeline-visits.json', JSON.stringify(timelineData));
|
||||
|
||||
// const timelineFilledMerged = fillAndMergeTimelineAggregation(timelineData, slice);
|
||||
// return timelineFilledMerged;
|
||||
// });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function executeAdvancedTimelineAggregation<T = {}>(options: Advanc
|
||||
console.log(JSON.stringify(aggregation, null, 2));
|
||||
}
|
||||
|
||||
const timeline: { _id: string, count: number & T }[] = await options.model.aggregate(aggregation);
|
||||
const timeline: { _id: string, count: number & T }[] = await options.model.aggregate(aggregation, { explain: options.debug === true });
|
||||
|
||||
return timeline;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user