mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-10-27 02:16:23 -04:00
- Replace `"use cache"` with `"use cache: remote"` on functions that run inside dynamic holes (`getContributions`, `getRepos`, `getPostStats`, `getCachedComments`) so entries are shared across server instances
- Switch comment and view server actions from `revalidatePath`/`revalidateTag` to `updateTag` + `refresh` for read-your-writes invalidation
- Extract a `commentsTag(pageSlug)` helper so each page's comment cache is expired independently instead of blowing the whole "comments" tag
- Refactor `getComments` to delegate to a cached inner function that throws on failure (so errors are never cached); `getCommentCount` now reuses that cache entry instead of issuing a separate COUNT query
- Drop `lib/data/views.ts` (`getAllViewCounts`) — the `/api/hits` route now calls `getPostStats()` instead
- Remove `revalidateTag("views")` from `incrementViews`; view counts in `getPostStats` are allowed to lag by a cache TTL
- Remove the `Suspense`/`Skeleton` wrapper on the projects page since `getContributions` is now a remote-cached call
31 lines
713 B
TypeScript
31 lines
713 B
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
import { getPostStats } from "@/lib/data/stats";
|
|
|
|
export const GET = async (): Promise<
|
|
NextResponse<{
|
|
total: {
|
|
hits: number;
|
|
};
|
|
pages: Array<{
|
|
slug: string;
|
|
hits: number;
|
|
}>;
|
|
}>
|
|
> => {
|
|
// note: while hits have been renamed to views in most places, this API shouldn't change due to it being snapshotted
|
|
const { views } = await getPostStats();
|
|
|
|
const total = {
|
|
hits: Object.values(views).reduce((acc, curr) => acc + curr, 0),
|
|
};
|
|
const pages = Object.entries(views).map(([slug, count]) => ({
|
|
slug,
|
|
hits: count,
|
|
}));
|
|
|
|
pages.sort((a, b) => b.hits - a.hits);
|
|
|
|
return NextResponse.json({ total, pages });
|
|
};
|