Skip to content

Commit

Permalink
change prisma random users logic
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lvax committed Oct 24, 2024
1 parent b745782 commit 9020d08
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@ import { prisma } from '$lib/server/prisma';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async () => {
// Fetch 6 random users
//fetch 6 random users
const userCount = await prisma.user.count();
const skip = Math.floor(Math.random() * userCount);
const users = await prisma.user.findMany({
take: 6,
skip: skip,
orderBy: {
id: 'asc'
},
where: {
id: {
in: (
await prisma.user.findMany({
select: { id: true },
orderBy: {
id: 'asc'
}
})
).map((user) => user.id)
}
id: 'desc'
}
});

Expand Down

0 comments on commit 9020d08

Please sign in to comment.