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

File diff suppressed because it is too large. Load diff
+20 -12
View File
@@ -4,21 +4,29 @@
import { asc } from "drizzle-orm";
import { apiJson } from "@/lib/api";
import { db, WebsiteRareValueCategories } from "@/lib/db";
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
export async function GET(_req: Request) {
try {
const data = await db
.select({
id: WebsiteRareValueCategories.id,
name: WebsiteRareValueCategories.name,
badge: WebsiteRareValueCategories.badge,
priority: WebsiteRareValueCategories.priority,
})
.from(WebsiteRareValueCategories)
.orderBy(
asc(WebsiteRareValueCategories.priority),
asc(WebsiteRareValueCategories.name),
);
const data = await redisCache(
apiCacheKey("values:categories"),
300,
async () =>
cacheSafe(
await db
.select({
id: WebsiteRareValueCategories.id,
name: WebsiteRareValueCategories.name,
badge: WebsiteRareValueCategories.badge,
priority: WebsiteRareValueCategories.priority,
})
.from(WebsiteRareValueCategories)
.orderBy(
asc(WebsiteRareValueCategories.priority),
asc(WebsiteRareValueCategories.name),
),
),
);
return apiJson({ data });
} catch {
+39 -29
View File
@@ -4,6 +4,7 @@
import { asc, count, eq } from "drizzle-orm";
import { apiError, apiJson, pagination, positiveBigInt } from "@/lib/api";
import { db, WebsiteRareValues } from "@/lib/db";
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
export async function GET(req: Request) {
const sp = new URL(req.url).searchParams;
@@ -24,36 +25,45 @@ export async function GET(req: Request) {
? eq(WebsiteRareValues.categoryId, categoryId)
: undefined;
const [totalRows, data] = await Promise.all([
db.select({ total: count() }).from(WebsiteRareValues).where(where),
db
.select({
id: WebsiteRareValues.id,
categoryId: WebsiteRareValues.categoryId,
itemId: WebsiteRareValues.itemId,
name: WebsiteRareValues.name,
creditValue: WebsiteRareValues.creditValue,
currencyValue: WebsiteRareValues.currencyValue,
currencyType: WebsiteRareValues.currencyType,
furnitureIcon: WebsiteRareValues.furnitureIcon,
})
.from(WebsiteRareValues)
.where(where)
.orderBy(asc(WebsiteRareValues.name))
.limit(take)
.offset(skip),
]);
const total = totalRows[0]?.total ?? 0;
return apiJson({
data,
meta: {
page,
perPage,
total,
lastPage: Math.max(1, Math.ceil(total / perPage)),
const data = await redisCache(
apiCacheKey(`values:${categoryId ?? "all"}:${page}:${perPage}`),
300,
async () => {
const [totalRows, rows] = await Promise.all([
db.select({ total: count() }).from(WebsiteRareValues).where(where),
db
.select({
id: WebsiteRareValues.id,
categoryId: WebsiteRareValues.categoryId,
itemId: WebsiteRareValues.itemId,
name: WebsiteRareValues.name,
creditValue: WebsiteRareValues.creditValue,
currencyValue: WebsiteRareValues.currencyValue,
currencyType: WebsiteRareValues.currencyType,
furnitureIcon: WebsiteRareValues.furnitureIcon,
})
.from(WebsiteRareValues)
.where(where)
.orderBy(asc(WebsiteRareValues.name))
.limit(take)
.offset(skip),
]);
return cacheSafe({
data: rows,
meta: {
page,
perPage,
total: totalRows[0]?.total ?? 0,
lastPage: Math.max(
1,
Math.ceil((totalRows[0]?.total ?? 0) / perPage),
),
},
});
},
});
);
return apiJson(data);
} catch {
// DB unreachable — never 500; return an empty, well-formed payload.
return apiJson(