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:
1 parent
54f2bc5e0c
commit
f285a7cd98
42 files changed
+1616
-1205
No files matched your search
@@ -16,9 +16,11 @@ type CategoryRow = {
|
||||
|
||||
export default async function RareValuesPage() {
|
||||
const t = await getTranslations("pages.rares");
|
||||
let categories: CategoryRow[] = [];
|
||||
try {
|
||||
categories = await db
|
||||
|
||||
// Categories, per-category rare counts and site settings are all
|
||||
// independent — run them concurrently instead of sequentially.
|
||||
const [categoryRows, grouped, badgesBase] = await Promise.all([
|
||||
db
|
||||
.select({
|
||||
id: WebsiteRareValueCategories.id,
|
||||
name: WebsiteRareValueCategories.name,
|
||||
@@ -29,29 +31,26 @@ export default async function RareValuesPage() {
|
||||
.orderBy(
|
||||
asc(WebsiteRareValueCategories.priority),
|
||||
asc(WebsiteRareValueCategories.name),
|
||||
);
|
||||
} catch {
|
||||
categories = [];
|
||||
}
|
||||
|
||||
// Per-category rare counts (grouped so we avoid N queries).
|
||||
const counts = new Map<string, number>();
|
||||
try {
|
||||
const grouped = await db
|
||||
)
|
||||
.catch((): CategoryRow[] => []),
|
||||
db
|
||||
.select({
|
||||
categoryId: WebsiteRareValues.categoryId,
|
||||
value: count(),
|
||||
})
|
||||
.from(WebsiteRareValues)
|
||||
.groupBy(WebsiteRareValues.categoryId);
|
||||
for (const g of grouped) {
|
||||
counts.set(String(g.categoryId), Number(g.value));
|
||||
}
|
||||
} catch {
|
||||
// leave counts empty -> shown as 0
|
||||
}
|
||||
.groupBy(WebsiteRareValues.categoryId)
|
||||
.catch(() => []),
|
||||
siteSettings.get("badges_path", ""),
|
||||
]);
|
||||
|
||||
const badgesBase = (await siteSettings.get("badges_path", "")) ?? "";
|
||||
const categories = categoryRows;
|
||||
|
||||
// Per-category rare counts (grouped so we avoid N queries).
|
||||
const counts = new Map<string, number>();
|
||||
for (const g of grouped) {
|
||||
counts.set(String(g.categoryId), Number(g.value));
|
||||
}
|
||||
|
||||
return (
|
||||
<main style={{ display: "grid", gap: "1.5rem" }}>
|
||||
|
||||
Reference in new issue
Block a user