Add performance optimizations and component refactors

- Cache read-heavy public API routes via redisCache (leaderboard, values,
  shop, articles, photos, guilds, teams, staff, users, home, radio, badges)
- Add single-flight and bounded-memory cache layer with unit tests
- Parallelize independent DB queries on search, rares, shop, staff, polls
  and profile pages
- Push radio points leaderboard aggregation to SQL with a LIMIT
- Split studio-client and import-furni-client into focused modules
- Clean up next.config.ts
This commit is contained in:
openhands committed 2026-08-17 22:02:21 +02:00
1 parent 54f2bc5e0c
commit f285a7cd98
42 files changed
+1616 -1205

No files matched your search

+34 -24
View File
@@ -1,6 +1,7 @@
import { count, desc } from "drizzle-orm";
import { apiJson, pagination } from "@/lib/api";
import { CameraWeb, db } from "@/lib/db";
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
/**
* GET /api/photos — recent community photos (camera_web), newest first.
@@ -12,31 +13,40 @@ export async function GET(req: Request) {
const { page, perPage, skip, take } = pagination(sp);
try {
const [totalRows, photos] = await Promise.all([
db.select({ total: count() }).from(CameraWeb),
db
.select({
id: CameraWeb.id,
userId: CameraWeb.userId,
url: CameraWeb.url,
timestamp: CameraWeb.timestamp,
})
.from(CameraWeb)
.orderBy(desc(CameraWeb.timestamp))
.limit(take)
.offset(skip),
]);
const total = totalRows[0]?.total ?? 0;
return apiJson({
data: photos,
meta: {
page,
perPage,
total,
lastPage: Math.max(1, Math.ceil(total / perPage)),
const data = await redisCache(
apiCacheKey(`photos:${page}:${perPage}`),
60,
async () => {
const [totalRows, photos] = await Promise.all([
db.select({ total: count() }).from(CameraWeb),
db
.select({
id: CameraWeb.id,
userId: CameraWeb.userId,
url: CameraWeb.url,
timestamp: CameraWeb.timestamp,
})
.from(CameraWeb)
.orderBy(desc(CameraWeb.timestamp))
.limit(take)
.offset(skip),
]);
return cacheSafe({
data: photos,
meta: {
page,
perPage,
total: totalRows[0]?.total ?? 0,
lastPage: Math.max(
1,
Math.ceil((totalRows[0]?.total ?? 0) / perPage),
),
},
});
},
});
);
return apiJson(data);
} catch {
// DB unavailable — return an empty payload instead of a 500.
return apiJson(