mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
aggregation optimization
This commit is contained in:
4
dashboard/.gitignore
vendored
4
dashboard/.gitignore
vendored
@@ -32,3 +32,7 @@ out.pdf
|
|||||||
|
|
||||||
# TESTS - TO REMOVE
|
# TESTS - TO REMOVE
|
||||||
tests
|
tests
|
||||||
|
|
||||||
|
# EXPLAINS MONGODB
|
||||||
|
|
||||||
|
explains
|
||||||
@@ -100,7 +100,8 @@ function goToUpgrade() {
|
|||||||
Limit reached
|
Limit reached
|
||||||
</div>
|
</div>
|
||||||
<div class="poppins text-[#fbbf24]">
|
<div class="poppins text-[#fbbf24]">
|
||||||
Litlyx cannot receive new data as you reached your plan's limit. Resume all the great features and collect even more data with a higher plan.
|
Litlyx cannot receive new data as you reached your plan's limit. Resume all the great
|
||||||
|
features and collect even more data with a higher plan.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
|||||||
import DateService from "@services/DateService";
|
import DateService from "@services/DateService";
|
||||||
import { executeTimelineAggregation, fillAndMergeTimelineAggregation } from "~/server/services/TimelineService";
|
import { executeTimelineAggregation, fillAndMergeTimelineAggregation } from "~/server/services/TimelineService";
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
const project_id = getRequestProjectId(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 (!to) return setResponseStatus(event, 400, 'to is required');
|
||||||
if (!slice) return setResponseStatus(event, 400, 'slice is required');
|
if (!slice) return setResponseStatus(event, 400, 'slice is required');
|
||||||
|
|
||||||
return await Redis.useCache({
|
// return await Redis.useCache({
|
||||||
key: `timeline:visits:${project_id}:${slice}:${from || 'none'}:${to || 'none'}`,
|
// key: `timeline:visits:${project_id}:${slice}:${from || 'none'}:${to || 'none'}`,
|
||||||
exp: TIMELINE_EXPIRE_TIME
|
// exp: TIMELINE_EXPIRE_TIME,
|
||||||
}, async () => {
|
// }, async () => {
|
||||||
const timelineData = await executeTimelineAggregation({
|
const timelineData = await executeTimelineAggregation({
|
||||||
projectId: project._id,
|
projectId: project._id,
|
||||||
model: VisitModel,
|
model: VisitModel,
|
||||||
from, to, slice
|
from, to, slice,
|
||||||
});
|
debug: true
|
||||||
const timelineFilledMerged = fillAndMergeTimelineAggregation(timelineData, slice);
|
|
||||||
return timelineFilledMerged;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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));
|
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;
|
return timeline;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const EventSchema = new Schema<TEvent>({
|
|||||||
metadata: Schema.Types.Mixed,
|
metadata: Schema.Types.Mixed,
|
||||||
session: { type: String },
|
session: { type: String },
|
||||||
flowHash: { type: String },
|
flowHash: { type: String },
|
||||||
created_at: { type: Date, default: () => Date.now() },
|
created_at: { type: Date, default: () => Date.now(), index: true },
|
||||||
})
|
})
|
||||||
|
|
||||||
export const EventModel = model<TEvent>('events', EventSchema);
|
export const EventModel = model<TEvent>('events', EventSchema);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const SessionSchema = new Schema<TSession>({
|
|||||||
flowHash: { type: String },
|
flowHash: { type: String },
|
||||||
duration: { type: Number, required: true, default: 0 },
|
duration: { type: Number, required: true, default: 0 },
|
||||||
updated_at: { type: Date, default: () => Date.now() },
|
updated_at: { type: Date, default: () => Date.now() },
|
||||||
created_at: { type: Date, default: () => Date.now() },
|
created_at: { type: Date, default: () => Date.now(), index: true },
|
||||||
})
|
})
|
||||||
|
|
||||||
export const SessionModel = model<TSession>('sessions', SessionSchema);
|
export const SessionModel = model<TSession>('sessions', SessionSchema);
|
||||||
|
|||||||
Reference in New Issue
Block a user