mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
rewrite
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
28
dashboard/server/api/timeline/events_stacked.post.ts
Normal file
28
dashboard/server/api/timeline/events_stacked.post.ts
Normal 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;
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user