C
C
cicwak2021-01-14 01:04:04
Django
cicwak, 2021-01-14 01:04:04

How to find which QuerySet is in the list c QuerySet?

Of course, the question may be asked incorrectly, but now I will explain everything.
5fff6b6615cdc675825593.png
There is a DB, with a large number of records (in theory> 100,000).
It is necessary to rank users by the highest value in the how_start column.
I was able to compile a general rating, but I could not find a specific user in this large database.

This is how I sorted the most frequently played users:

most_games_player = profiles.objects.order_by('-how_start')

Everything works correctly, and moreover, quickly!

But I wanted to find the user's place in this rating, the question arose, how?
I started looking for information, but did not find the answer.

I tried with this method:
player = list(most_games_player).index(most_games_player.get(user_id=user_id))

Everything works, though. There is one thing, but it works slowly (very even), for 70,000 users - 1 second was spent, this is quite a lot (as for me), is there any way to optimize this method, or are there built-in methods in django.model?

The question is what, in order to find a specific user in most_games_player, for example with id==555.

Thank you for your attention

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2021-01-14
@deliro

Calculate how many users have a higher rating than the one you are looking for

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question