perf: optimize CMS queries, caching, and asset delivery
Database: - Add missing indexes (users.credits, users_currency(type,amount), users_settings.respects_received, camera_web.timestamp, messenger_offline.user_id) via migrations 0020/0021 - Use partial .select() everywhere instead of SELECT * (tickets, users, rooms, audit logs, catalog tree, polls, radio, password reset) - Add queryPrepared/queryPreparedOne (server-side prepared statements) and switch the login check to a prepared statement; drop dead cache options from the pool config - Raise total_users/total_rooms COUNT(*) cache TTL to 5m Caching: - Consolidate the three cache helpers (cached, redisCache, cachedQuery) into a single memory-first implementation backed by Redis - invalidateKey now clears the in-process cache as well as Redis - Cache homepage sections, news list, and leaderboard tabs; share one news_list cache key between homepage and news archive - siteSettings: in-process cache with TTL so repeated getters no longer pay a Redis round-trip per call - Share a 10s poll cache across all radio SSE connections - Normalize timestamps after cache reads (Redis JSON round-trip) Assets: - Enable AVIF/WebP via images.formats and remove unoptimized from news covers and the homepage hero (149KB jpg) with proper sizes/priority - Support ?format=webp|avif|png in the /imaging proxy via sharp Other: - Fix pnpm supply-chain minimumReleaseAge failures by excluding the freshly-published packages (next 16.3.1, hookform resolvers 5.8.0, resend 6.20.0) - Remove unused before/after fields from housekeeping AuditEntry
This commit is contained in:
1 parent
dc9e5a567c
commit
e5ec3c1f06
29 files changed
+532
-322
No files matched your search
+16
-33
@@ -18,7 +18,6 @@ import {
|
||||
UsersBadges,
|
||||
UsersSettings,
|
||||
WebsiteLoginLogs,
|
||||
WebsiteSetting,
|
||||
} from "@/lib/db";
|
||||
import { avatarImageUrl } from "@/lib/format";
|
||||
import { resolveHotelName } from "@/lib/hotel-name";
|
||||
@@ -85,9 +84,9 @@ export default async function MePage({
|
||||
const [
|
||||
userRows,
|
||||
hotelName,
|
||||
neededRows,
|
||||
amountRows,
|
||||
currencyRows,
|
||||
neededRaw,
|
||||
rewardAmountRaw,
|
||||
currencySettings,
|
||||
alertRaw,
|
||||
recentRooms,
|
||||
badges,
|
||||
@@ -112,29 +111,12 @@ export default async function MePage({
|
||||
.where(eq(User.id, userId))
|
||||
.limit(1),
|
||||
resolveHotelName(),
|
||||
db
|
||||
.select({ value: WebsiteSetting.value })
|
||||
.from(WebsiteSetting)
|
||||
.where(eq(WebsiteSetting.key, "referrals_needed"))
|
||||
.limit(1)
|
||||
.catch(() => []),
|
||||
db
|
||||
.select({ value: WebsiteSetting.value })
|
||||
.from(WebsiteSetting)
|
||||
.where(eq(WebsiteSetting.key, "referral_reward_amount"))
|
||||
.limit(1)
|
||||
.catch(() => []),
|
||||
db
|
||||
.select({ value: WebsiteSetting.value })
|
||||
.from(WebsiteSetting)
|
||||
.where(
|
||||
inArray(WebsiteSetting.key, [
|
||||
"referral_reward_currency_type",
|
||||
"referral_reward_currency",
|
||||
]),
|
||||
)
|
||||
.limit(1)
|
||||
.catch(() => []),
|
||||
siteSettings.get("referrals_needed", "5"),
|
||||
siteSettings.get("referral_reward_amount", "30"),
|
||||
siteSettings.getMany([
|
||||
"referral_reward_currency_type",
|
||||
"referral_reward_currency",
|
||||
]),
|
||||
siteSettings.get("hotel_alert_banner", ""),
|
||||
db
|
||||
.select({
|
||||
@@ -191,9 +173,6 @@ export default async function MePage({
|
||||
]);
|
||||
|
||||
const user = userRows[0] ?? null;
|
||||
const neededRaw = neededRows[0] ?? null;
|
||||
const amountRaw = amountRows[0] ?? null;
|
||||
const currencyRaw = currencyRows[0] ?? null;
|
||||
const lastWebLogin = lastWebLoginRows[0] ?? null;
|
||||
const userSettings = userSettingsRows[0] ?? null;
|
||||
const friendCount = Number(friendCountRows[0]?.value ?? 0);
|
||||
@@ -203,9 +182,13 @@ export default async function MePage({
|
||||
|
||||
if (!user) throw new Error("user-not-found");
|
||||
|
||||
const needed = Number.parseInt(neededRaw?.value ?? "5", 10) || 5;
|
||||
const rewardAmount = Number.parseInt(amountRaw?.value ?? "30", 10) || 0;
|
||||
const rewardCurrency = (currencyRaw?.value ?? "diamonds")
|
||||
const needed = Number.parseInt(neededRaw ?? "5", 10) || 5;
|
||||
const rewardAmount = Number.parseInt(rewardAmountRaw ?? "30", 10) || 0;
|
||||
const rewardCurrency = (
|
||||
currencySettings.referral_reward_currency_type ??
|
||||
currencySettings.referral_reward_currency ??
|
||||
"diamonds"
|
||||
)
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
|
||||
|
||||
Reference in new issue
Block a user