Is there the possibility of getting
Is there the possibility of getting someone's position (index in the table) in an efficient way too?
14 Replies
Can you tell me more about the scnerio here? What exactly are you trying to achieve ?
@CPTRedHawk
hi
Imagine the following scenario: I have a competition list where the one with the most points wins, based on that I need to get that user's index in the ranking, basically that's it
but iterating through 30 thousand users is a very large consumption of bandwidth, so I need to optimize this to know the position of each one
this is possible but not easy -- it requires a special data structure to keep track of ranks/positions/indexes. i have a prototype that's almost ready for consumption, let us know if you want to use it 🙂
yes
need 🙂
i suppose there could be some kind of memory management using heap or stack storage methods?
i'm interested
I'm an advanced user, so I can get it easily (I think haha)
It really takes a lot of time to iterate through all the indexes in the table with collect(), the bandwidth consumes a lot
if i just reply to this without the context of yours.i was going to suggest keeping the positions in a seperate table and calculating them as it changes.
but then i thought if competition is live and indexes are changing continuously.
there'd be ton of mutations and query updates. which isn't suitable.
if working with something like a dashboard to show user an overview of data then it can work like that. idk the exact use case here.
but convex team a goat. i'm sure there's something more interesting to see here.
It's in real time, so the ideal would be to find a solution for this through indexes, iterating over the entire table is ridiculous and anti-standard
anti-pattern
yep the outline of the solution is to build a btree with counts on each node, so you can figure out the rank of a key just by traversing down the tree in O(log n) time
i was thinking more of a segment tree if we want to also get aggregated scores of a particular user against others in the same child?
can we use indexes (pretending) inside childrens somehow?
Do you have any example?
here's an old repo with the proof of concept https://github.com/ldanilek/aggregate/tree/non-components
GitHub
GitHub - ldanilek/aggregate at non-components
Contribute to ldanilek/aggregate development by creating an account on GitHub.
we plan on shipping a more modern, easier-to-install version soon
thanks bro