Unfortunately Prisma doesn't support this kind of complex query.
I'm a bit wary of shifting complexity into an SQL query like this one. It makes the code quite a bit less approachable.
Another option I've considered is a more eventually consistent approach where a periodic job computes the quizzes completed with each other user and stores it in something like redis. But since we currently have no worker or redis setup I thought that would blow the scope of this work out completely.
Unfortunately Prisma doesn't support this kind of complex query. I'm a bit wary of shifting complexity into an SQL query like this one. It makes the code quite a bit less approachable.
Another option I've considered is a more eventually consistent approach where a periodic job computes the quizzes completed with each other user and stores it in something like redis. But since we currently have no worker or redis setup I thought that would blow the scope of this work out completely.