mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
Merge pull request #28 from AlexHelo/fix/cloudflare-caching-and-query-performance
Fix Cloudflare RSC caching bug and reduce database load
This commit is contained in:
commit
b00ce4dc3b
4 changed files with 18 additions and 19 deletions
|
|
@ -5,6 +5,17 @@ const nextConfig: NextConfig = {
|
||||||
images: {
|
images: {
|
||||||
unoptimized: true,
|
unoptimized: true,
|
||||||
},
|
},
|
||||||
|
async headers() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
// Prevent Cloudflare from serving cached HTML for RSC navigation requests
|
||||||
|
source: "/:path*",
|
||||||
|
headers: [
|
||||||
|
{ key: "Vary", value: "RSC, Next-Router-State-Tree, Next-Router-Prefetch" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ model Mii {
|
||||||
@@index([gender])
|
@@index([gender])
|
||||||
@@index([makeup])
|
@@index([makeup])
|
||||||
@@index([quarantined, id])
|
@@index([quarantined, id])
|
||||||
|
@@index([in_queue, quarantined, createdAt(sort: Desc)])
|
||||||
@@map("miis")
|
@@map("miis")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,6 @@ export default async function MiiList({ searchParams, userId, parentPage }: Prop
|
||||||
const skip = (page - 1) * limit;
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
let totalCount: number;
|
let totalCount: number;
|
||||||
let filteredCount: number;
|
|
||||||
let miis: Prisma.MiiGetPayload<{ select: typeof select }>[];
|
let miis: Prisma.MiiGetPayload<{ select: typeof select }>[];
|
||||||
|
|
||||||
if (sort === "random") {
|
if (sort === "random") {
|
||||||
|
|
@ -119,7 +118,6 @@ export default async function MiiList({ searchParams, userId, parentPage }: Prop
|
||||||
});
|
});
|
||||||
|
|
||||||
totalCount = matchingIds.length;
|
totalCount = matchingIds.length;
|
||||||
filteredCount = Math.max(0, Math.min(limit, totalCount - skip));
|
|
||||||
|
|
||||||
if (matchingIds.length === 0) return;
|
if (matchingIds.length === 0) return;
|
||||||
|
|
||||||
|
|
@ -155,14 +153,13 @@ export default async function MiiList({ searchParams, userId, parentPage }: Prop
|
||||||
orderBy = [{ createdAt: "desc" }, { name: "asc" }];
|
orderBy = [{ createdAt: "desc" }, { name: "asc" }];
|
||||||
}
|
}
|
||||||
|
|
||||||
[totalCount, filteredCount, miis] = await Promise.all([
|
[totalCount, miis] = await Promise.all([
|
||||||
prisma.mii.count({ where: { ...where, userId } }),
|
prisma.mii.count({ where: { ...where, userId } }),
|
||||||
prisma.mii.count({ where, skip, take: limit }),
|
|
||||||
prisma.mii.findMany({
|
prisma.mii.findMany({
|
||||||
where,
|
where,
|
||||||
orderBy,
|
orderBy,
|
||||||
select,
|
select,
|
||||||
skip: (page - 1) * limit,
|
skip,
|
||||||
take: limit,
|
take: limit,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
@ -174,19 +171,8 @@ export default async function MiiList({ searchParams, userId, parentPage }: Prop
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="bg-amber-50 border-2 border-amber-500 rounded-2xl shadow-lg p-4 flex justify-between items-center gap-2 mb-2 max-md:flex-col">
|
<div className="bg-amber-50 border-2 border-amber-500 rounded-2xl shadow-lg p-4 flex justify-between items-center gap-2 mb-2 max-md:flex-col">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{totalCount == filteredCount ? (
|
|
||||||
<>
|
|
||||||
<span className="text-2xl font-bold text-amber-900">{totalCount}</span>
|
<span className="text-2xl font-bold text-amber-900">{totalCount}</span>
|
||||||
<span className="text-lg text-amber-700">{totalCount === 1 ? "Mii" : "Miis"}</span>
|
<span className="text-lg text-amber-700">{totalCount === 1 ? "Mii" : "Miis"}</span>
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<span className="text-2xl font-bold text-amber-900">{filteredCount}</span>
|
|
||||||
<span className="text-sm text-amber-700">of</span>
|
|
||||||
<span className="text-lg font-semibold text-amber-800">{totalCount}</span>
|
|
||||||
<span className="text-lg text-amber-700">Miis</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative flex items-center justify-end gap-2 w-full md:max-w-2/3 max-md:justify-center">
|
<div className="relative flex items-center justify-end gap-2 w-full md:max-w-2/3 max-md:justify-center">
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,10 @@ export class RateLimit {
|
||||||
|
|
||||||
return { success, limit: this.maxRequests, remaining, expires: expireAt };
|
return { success, limit: this.maxRequests, remaining, expires: expireAt };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// Fail open — don't block users when Redis is unreachable
|
||||||
console.error("Rate limit check failed", error);
|
console.error("Rate limit check failed", error);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: true,
|
||||||
limit: this.maxRequests,
|
limit: this.maxRequests,
|
||||||
remaining: this.maxRequests,
|
remaining: this.maxRequests,
|
||||||
expires: expireAt,
|
expires: expireAt,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue