diff --git a/dashboard/.gitignore b/dashboard/.gitignore index 98a6c70..12f81be 100644 --- a/dashboard/.gitignore +++ b/dashboard/.gitignore @@ -31,4 +31,8 @@ logs out.pdf # TESTS - TO REMOVE -tests \ No newline at end of file +tests + +# EXPLAINS MONGODB + +explains \ No newline at end of file diff --git a/dashboard/pages/index.vue b/dashboard/pages/index.vue index fe320b0..a40b126 100644 --- a/dashboard/pages/index.vue +++ b/dashboard/pages/index.vue @@ -100,7 +100,8 @@ function goToUpgrade() { Limit reached
- 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.
@@ -111,7 +112,7 @@ function goToUpgrade() {
- + @@ -143,7 +144,7 @@ function goToUpgrade() { --> - +
@@ -151,13 +152,13 @@ function goToUpgrade() {
- +
-
+
@@ -187,7 +188,7 @@ function goToUpgrade() {
-
+
diff --git a/dashboard/server/api/metrics/[project_id]/timeline/visits.post.ts b/dashboard/server/api/metrics/[project_id]/timeline/visits.post.ts index 0e49ec2..e9845e7 100644 --- a/dashboard/server/api/metrics/[project_id]/timeline/visits.post.ts +++ b/dashboard/server/api/metrics/[project_id]/timeline/visits.post.ts @@ -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; + // }); + diff --git a/dashboard/server/services/TimelineService.ts b/dashboard/server/services/TimelineService.ts index 88c6e1c..137ee9c 100644 --- a/dashboard/server/services/TimelineService.ts +++ b/dashboard/server/services/TimelineService.ts @@ -46,7 +46,7 @@ export async function executeAdvancedTimelineAggregation(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; diff --git a/shared/schema/metrics/EventSchema.ts b/shared/schema/metrics/EventSchema.ts index a0c17d2..2f98a59 100644 --- a/shared/schema/metrics/EventSchema.ts +++ b/shared/schema/metrics/EventSchema.ts @@ -15,7 +15,7 @@ const EventSchema = new Schema({ 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('events', EventSchema); diff --git a/shared/schema/metrics/SessionSchema.ts b/shared/schema/metrics/SessionSchema.ts index 9f3cf71..8535e11 100644 --- a/shared/schema/metrics/SessionSchema.ts +++ b/shared/schema/metrics/SessionSchema.ts @@ -16,7 +16,7 @@ const SessionSchema = new Schema({ 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('sessions', SessionSchema);