aggregation optimization

This commit is contained in:
Emily
2024-09-02 18:36:52 +02:00
parent d499aa2f39
commit c003b655ec
6 changed files with 32 additions and 21 deletions

View File

@@ -32,3 +32,7 @@ out.pdf
# TESTS - TO REMOVE
tests
# EXPLAINS MONGODB
explains

View File

@@ -100,7 +100,8 @@ function goToUpgrade() {
Limit reached
</div>
<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>
@@ -111,7 +112,7 @@ function goToUpgrade() {
</div>
<DashboardTopSection></DashboardTopSection>
<DashboardTopSection></DashboardTopSection>
<DashboardTopCards :key="refreshKey"></DashboardTopCards>
@@ -151,13 +152,13 @@ function goToUpgrade() {
<DashboardWebsitesBarCard :key="refreshKey"></DashboardWebsitesBarCard>
</div>
<div class="flex-1">
<DashboardEventsBarCard :key="refreshKey"></DashboardEventsBarCard>
<DashboardEventsBarCard :key="refreshKey"></DashboardEventsBarCard>
</div>
</div>
</div>
<div class="flex w-full justify-center mt-6 px-6">
<div class="flex w-full justify-center mt-6 px-6">
<div class="flex w-full gap-6 flex-col xl:flex-row">
<div class="flex-1">
<DashboardReferrersBarCard :key="refreshKey"></DashboardReferrersBarCard>

View File

@@ -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;
// });

View File

@@ -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;

View File

@@ -15,7 +15,7 @@ const EventSchema = new Schema<TEvent>({
metadata: Schema.Types.Mixed,
session: { 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);

View File

@@ -16,7 +16,7 @@ const SessionSchema = new Schema<TSession>({
flowHash: { type: String },
duration: { type: Number, required: true, default: 0 },
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);