This commit is contained in:
Emily
2024-10-07 15:26:57 +02:00
parent c2846ca595
commit b27cacf4e6
50 changed files with 512 additions and 583 deletions

View File

@@ -14,7 +14,7 @@ export default defineEventHandler(async event => {
const { pid, from, to, slice, project_id } = data;
const cacheKey = `timeline:bouncing_rate:${pid}:${from}:${to}`;
const cacheKey = `timeline:bouncing_rate:${pid}:${slice}:${from}:${to}`;
const cacheExp = 60 * 60; //1 hour
return await Redis.useCacheV2(cacheKey, cacheExp, async (noStore, updateExp) => {

View File

@@ -9,7 +9,7 @@ export default defineEventHandler(async event => {
const { pid, from, to, slice, project_id } = data;
const cacheKey = `timeline:events:${pid}:${from}:${to}`;
const cacheKey = `timeline:events:${pid}:${slice}:${from}:${to}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {

View File

@@ -0,0 +1,28 @@
import { EventModel } from "@schema/metrics/EventSchema";
import { Redis, TIMELINE_EXPIRE_TIME } from "~/server/services/CacheService";
import { executeAdvancedTimelineAggregation} from "~/server/services/TimelineService";
export default defineEventHandler(async event => {
const data = await getRequestData(event, { requireSchema: false, requireSlice: true });
if (!data) return;
const { from, to, slice, project_id } = data;
return await Redis.useCache({ key: `timeline:events_stacked:${project_id}:${slice}:${from || 'none'}:${to || 'none'}`, exp: TIMELINE_EXPIRE_TIME }, async () => {
const timelineStackedEvents = await executeAdvancedTimelineAggregation<{ name: String }>({
model: EventModel,
projectId: project_id,
from, to, slice,
customProjection: { name: "$_id.name" },
customIdGroup: { name: '$name' },
})
// const filledDates = DateService.createBetweenDates(from, to, slice);
// const merged = DateService.mergeFilledDates(filledDates.dates, timelineStackedEvents, '_id', slice, { count: 0, name: '' });
return timelineStackedEvents;
});
});

View File

@@ -9,7 +9,7 @@ export default defineEventHandler(async event => {
const { pid, from, to, slice, project_id } = data;
const cacheKey = `timeline:sessions:${pid}:${from}:${to}`;
const cacheKey = `timeline:sessions:${pid}:${slice}:${from}:${to}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {

View File

@@ -9,7 +9,7 @@ export default defineEventHandler(async event => {
const { pid, from, to, slice, project_id } = data;
const cacheKey = `timeline:sessions_duration:${pid}:${from}:${to}`;
const cacheKey = `timeline:sessions_duration:${pid}:${slice}:${from}:${to}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {

View File

@@ -9,7 +9,7 @@ export default defineEventHandler(async event => {
const { pid, from, to, slice, project_id } = data;
const cacheKey = `timeline:visits:${pid}:${from}:${to}`;
const cacheKey = `timeline:visits:${pid}:${slice}:${from}:${to}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {