cache public stats

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-02 10:12:12 +02:00
parent 88b983a7ae
commit 838c38d23e
2 changed files with 13 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ import { ALink } from '@/components/ui/button';
import { chQuery, TABLE_NAMES } from '@openpanel/db';
import { cacheable } from '../../../../packages/redis';
import AnimatedText from './animated-text';
import { Heading1, Lead2 } from './copy';
@@ -13,10 +14,16 @@ function shortNumber(num: number) {
if (num >= 1e12) return +(num / 1e12).toFixed(1) + 'T';
}
export async function Hero() {
const getProjectsWithCount = cacheable(async () => {
const projects = await chQuery<{ project_id: string; count: number }>(
`SELECT project_id, count(*) as count from ${TABLE_NAMES.events} GROUP by project_id order by count()`
);
return projects;
}, 60 * 10);
export async function Hero() {
const projects = await getProjectsWithCount();
const projectCount = projects.length;
const eventCount = projects.reduce((acc, { count }) => acc + count, 0);
return (