I want to list all documents since 100 limit is removed I believe but without hardcoding the value- .. like i am making a leaderboard so i need to find user's rank after listing all the documents ;-;
my current approach is to fetch 100 documents and only fetch more if user doesnt exist in those 100 docs (cursor pagination)
keep doing it till user is found/no user
But you'll still going to face a limit of the 5,000 totally
Oh, yes that would be the right way
oh but the code kinda started to getting complicated so thought i maybe need smth else
perhaps thats the best way
Can you elaborate more and the use-case
So like I wanna fetch top 10 users in leaderboard
With that the rank of current user viewing the leaderboard
Okay, can you show me a simple row?
as in single document data?
Yes,
here are multiple rows since its only 2 columns
i basically sort them in descending order
for highscore
Got you.
With the available Appwrite query function there it seems there no other way then you suggested.
Meaning as we can't get sum
and group-by
in the queries then the best way would be to use cursor pagination.
Though, It may be good to create another collection and within it adding totals for top 1K users.
So, Something like this.
Top scores collection A new collection with top 1K users. each row will contain user_id, total_highscroe
The reason there is need for top 1K is for quick access in the Summary function.
Summary function Here we can choose one of these approaches
In case the scores collection get a lot of inserts command, Will run the Summary function hourly.
In case there fair amount of numbers of inserts we can let the function run after any insert
event into the scores tables. ( because we're using in-ram variable then it will take less then second most of the time )
The function will utilize an in-ram variable that will hold all the TopScores collection , is size should be about 30KB in the RAM.
Then any time a new score is being added the function will first check to see if there is any matching user id in the in-ram variable, if so it will just add-it and resort the array.
If the new user id is not in the variable then it will be added to a second variable, that will count the value for the IDs that are not in the top 1K.
Then this is the logic when there is a need to recreate the first list.
If any new listing in second variable value + the last value of the the top is more then one of the top 10 then it's time to refetch the list from the database.
if(newScores[current_id] + topScores[topScores.length - 1] > topScores[9])
await refetch();
Current user For the current user score we will create another function which select only by the current user id, and will use regular pagination. Or, cursor in case it's common for user to have more then 5,000 scores.
ohh thanks for the detailed approach :)
<:appwriteupvote:899677724615016528>
Recommended threads
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...
- What Query's are valid for GetDocument?
Documentation shows that Queries are valid here, but doesn't explain which queries are valid. At first I presumed this to be a bug, but before creating a githu...
- Appwrite exception: user_unauthorized, t...
After refreshing the app it is working perfectly