fix: dashboard improvements and query speed improvements

This commit is contained in:
Carl-Gerhard Lindesvärd
2026-01-09 14:42:11 +01:00
parent 4867260ece
commit cabfb1f3f0
49 changed files with 3398 additions and 950 deletions

View File

@@ -35,7 +35,7 @@ import {
} from '@openpanel/validation';
import { round } from '@openpanel/common';
import { ChartEngine } from '@openpanel/db';
import { AggregateChartEngine, ChartEngine } from '@openpanel/db';
import {
differenceInDays,
differenceInMonths,
@@ -414,6 +414,42 @@ export const chartRouter = createTRPCRouter({
// Use new chart engine
return ChartEngine.execute(input);
}),
aggregate: publicProcedure
.input(zChartInput)
.query(async ({ input, ctx }) => {
if (ctx.session.userId) {
const access = await getProjectAccess({
projectId: input.projectId,
userId: ctx.session.userId,
});
if (!access) {
const share = await db.shareOverview.findFirst({
where: {
projectId: input.projectId,
},
});
if (!share) {
throw TRPCAccessError('You do not have access to this project');
}
}
} else {
const share = await db.shareOverview.findFirst({
where: {
projectId: input.projectId,
},
});
if (!share) {
throw TRPCAccessError('You do not have access to this project');
}
}
// Use aggregate chart engine (optimized for bar/pie charts)
return AggregateChartEngine.execute(input);
}),
cohort: protectedProcedure
.input(
z.object({

View File

@@ -15,7 +15,7 @@ import {
getEventList,
getEventMetasCached,
getSettingsForProject,
overviewService,
pagesService,
sessionService,
} from '@openpanel/db';
import {
@@ -324,28 +324,17 @@ export const eventRouter = createTRPCRouter({
search: z.string().optional(),
range: zRange,
interval: zTimeInterval,
filters: z.array(zChartEventFilter).default([]),
}),
)
.query(async ({ input }) => {
const { timezone } = await getSettingsForProject(input.projectId);
const { startDate, endDate } = getChartStartEndDate(input, timezone);
if (input.search) {
input.filters.push({
id: 'path',
name: 'path',
value: [input.search],
operator: 'contains',
});
}
return overviewService.getTopPages({
return pagesService.getTopPages({
projectId: input.projectId,
filters: input.filters,
startDate,
endDate,
cursor: input.cursor || 1,
limit: input.take,
timezone,
search: input.search,
});
}),

View File

@@ -10,6 +10,7 @@ import {
overviewService,
zGetMetricsInput,
zGetTopGenericInput,
zGetTopGenericSeriesInput,
zGetTopPagesInput,
zGetUserJourneyInput,
} from '@openpanel/db';
@@ -305,6 +306,26 @@ export const overviewRouter = createTRPCRouter({
return current;
}),
topGenericSeries: publicProcedure
.input(
zGetTopGenericSeriesInput.omit({ startDate: true, endDate: true }).extend({
startDate: z.string().nullish(),
endDate: z.string().nullish(),
range: zRange,
}),
)
.use(cacher)
.query(async ({ input }) => {
const { timezone } = await getSettingsForProject(input.projectId);
const { current } = await getCurrentAndPrevious(
{ ...input, timezone },
false,
timezone,
)(overviewService.getTopGenericSeries.bind(overviewService));
return current;
}),
userJourney: publicProcedure
.input(
zGetUserJourneyInput.omit({ startDate: true, endDate: true }).extend({