MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / stats

Function stats

apps/api/src/controllers/misc.controller.ts:464–480  ·  view source on GitHub ↗
(request: FastifyRequest, reply: FastifyReply)

Source from the content-addressed store, hash-verified

462}
463
464export async function stats(request: FastifyRequest, reply: FastifyReply) {
465 const res = await getCache('api:stats', 60 * 60, async () => {
466 const projects = await chQuery<{ project_id: string; count: number }>(
467 `SELECT project_id, count(*) as count from ${TABLE_NAMES.events} GROUP by project_id order by count()`,
468 );
469 const last24h = await chQuery<{ count: number }>(
470 `SELECT count(*) as count from ${TABLE_NAMES.events} WHERE created_at > now() - interval '24 hours'`,
471 );
472 return { projects, last24hCount: last24h[0]?.count || 0 };
473 });
474
475 reply.status(200).send({
476 projectsCount: res.projects.length,
477 eventsCount: res.projects.reduce((acc, { count }) => acc + count, 0),
478 eventsLast24hCount: res.last24hCount,
479 });
480}
481
482export async function getGeo(request: FastifyRequest, reply: FastifyReply) {
483 const { ip, header } = getClientIpFromHeaders(request.headers);

Callers

nothing calls this directly

Calls 2

getCacheFunction · 0.90
sendMethod · 0.45

Tested by

no test coverage detected