hello everyone. i was wondering if there is any be...
# orm-help
s
hello everyone. i was wondering if there is any better way to get an index without having to fetch the whole table, i am currently doing this:
Copy code
const leveling = await prisma.leveling.findMany({ orderBy: { totalXp: "desc" } })
const index = leveling.findIndex((l) => l.userId === user.id)
the problem with it, is that as the table scales, finding the index is going to become very slow as its fetching the whole table.
r
@Seren_Modz 21 👋 You can directly use a
where
condition to find the value and return if it matches.
s
where
wouldn't find the index though, its not really the user data I want to get as shown above, i am currently using
Array#findIndex()
to find the index of the user, which then is used to show their rank position on their rank card, then there not having to look at the leaderboard