Skip to content

Commit

Permalink
fix(web): memoize event count properly
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt committed Sep 11, 2024
1 parent 0ff0c8a commit 1ca23b5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions apps/web/src/server/trpc/router/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AbbyEventType } from "@tryabby/core";
import dayjs from "dayjs";
import { getBaseEventsByInterval, TIME_INTERVAL } from "lib/events";
import memoize from "memoize";
import type { Context } from "../context";
import { prisma } from "server/db/client";

export const getEventData = memoize(
async (testId: string, interval: string, potentialVariants: string[]) => {
Expand Down Expand Up @@ -327,15 +327,15 @@ export const eventRouter = router({
};
}),
getEventCount: publicProcedure.query(async ({ ctx }) => {
return await getTotalEventCount(ctx);
return await getTotalEventCount();
}),
});

const getTotalEventCount = memoize(
async (ctx: Context) => {
async () => {
const [eventCount, apiRequestCount] = await Promise.all([
ctx.prisma.event.count(),
ctx.prisma.apiRequest.count(),
prisma.event.count(),
prisma.apiRequest.count(),
]);
return eventCount + apiRequestCount;
},
Expand Down

0 comments on commit 1ca23b5

Please sign in to comment.