Add performance optimizations and component refactors
CI / check (push) Successful in 34s
CI / release (push) Skipped
CI / deploy (push) Successful in 1m23s

- 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

+28 -15
View File
@@ -1,33 +1,46 @@
import { eq } from "drizzle-orm";
import { apiJson } from "@/lib/api";
import { db, User } from "@/lib/db";
import { apiCacheKey, redisCache } from "@/lib/redis-cache";
import { siteSettings } from "@/lib/services/site-settings";
// Current on-air DJ. The DJ is set manually via the radio_current_dj_id setting
// (Manual DJ user ID). When set, resolve that user's username/look; otherwise
// there is no DJ on air. Mirrors the AtomCMS radio "on air" widget.
// The radio widget polls this endpoint frequently — a short cache avoids a DB
// hit per poll. The DJ only changes when a moderator switches it manually.
const GET_TTL_SECONDS = 5;
export async function GET(_req: Request) {
try {
const raw = await siteSettings.get("radio_current_dj_id", "");
const id = Number(raw);
const dj = await redisCache(
apiCacheKey("radio:current-dj"),
GET_TTL_SECONDS,
async () => {
const raw = await siteSettings.get("radio_current_dj_id", "");
const id = Number(raw);
// No DJ configured (empty / non-numeric / zero).
if (!raw || !Number.isFinite(id) || id <= 0) {
return apiJson({ dj: null });
}
// No DJ configured (empty / non-numeric / zero).
if (!raw || !Number.isFinite(id) || id <= 0) {
return null;
}
const [user] = await db
.select({ username: User.username, look: User.look })
.from(User)
.where(eq(User.id, id))
.limit(1);
const [user] = await db
.select({ username: User.username, look: User.look })
.from(User)
.where(eq(User.id, id))
.limit(1);
if (!user) {
return apiJson({ dj: null });
}
if (!user) {
return null;
}
return apiJson({ dj: { username: user.username, look: user.look } });
return { username: user.username, look: user.look };
},
);
return apiJson({ dj });
} catch {
// DB / settings unavailable — no DJ rather than a 500.
return apiJson({ dj: null }, { status: 200 });