Add in-memory caching for online count, enable compression, and add staleTimes for router cache

This commit is contained in:
openhands committed 2026-07-09 18:24:58 +02:00
1 parent b058a3827b
commit deac10e00a
5 files changed
+51 -10

No files matched your search

+4 -4
View File
@@ -4,16 +4,16 @@
// { count: 0 } (never 500) on DB failure.
import { apiJson } from "@/lib/api";
import { cached } from "@/lib/cache";
import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
export async function GET(_req: Request) {
try {
const count = await prisma.user.count({
where: { online: "1" },
});
const count = await cached("online_count", 10_000, () =>
prisma.user.count({ where: { online: "1" } }),
);
return apiJson({ count });
} catch {
return apiJson({ count: 0 });