fix: random sort failing with pagination

This commit is contained in:
trafficlunar 2026-02-03 16:18:27 +00:00
parent 98fffcc396
commit 4f9a6b4c45
2 changed files with 5 additions and 6 deletions

View file

@ -97,9 +97,6 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
let list: Prisma.MiiGetPayload<{ select: typeof select }>[];
if (sort === "random") {
// Use seed for consistent random results
const randomSeed = seed || crypto.randomInt(0, 1_000_000_000);
// Get all IDs that match the where conditions
const matchingIds = await prisma.mii.findMany({
where,
@ -107,10 +104,12 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
});
totalCount = matchingIds.length;
filteredCount = Math.min(matchingIds.length, limit);
filteredCount = Math.max(0, Math.min(limit, totalCount - skip));
if (matchingIds.length === 0) return;
// Use seed for consistent random results
const randomSeed = seed || crypto.randomInt(0, 1_000_000_000);
const rng = seedrandom(randomSeed.toString());
// Randomize all IDs using the Durstenfeld algorithm
@ -120,7 +119,7 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
}
// Convert to number[] array
const selectedIds = matchingIds.slice(0, limit).map((i) => i.id);
const selectedIds = matchingIds.slice(skip, skip + limit).map((i) => i.id);
list = await prisma.mii.findMany({
where: {

View file

@ -205,7 +205,7 @@ export default function QrScanner({ isOpen, setIsOpen, setQrBytesRaw }: Props) {
<div className="relative w-full aspect-square">
{!permissionGranted && (
<div className="absolute inset-0 flex flex-col items-center justify-center rounded-2xl bg-amber-50 border-2 border-amber-500 text-center p-8">
<div className="absolute inset-0 z-20 flex flex-col items-center justify-center rounded-2xl bg-amber-50 border-2 border-amber-500 text-center p-8">
<p className="text-red-400 font-bold text-lg mb-2">Camera access denied</p>
<p className="text-gray-600">Please allow camera access in your browser settings to scan QR codes</p>
<button type="button" onClick={requestPermission} className="pill button text-xs mt-2 py-0.5! px-2!">