Is there any ways to get the amount of stored data in ordered datastore?
Thank you
Is there any ways to get the amount of stored data in ordered datastore?
Thank you
Not natively. You’d have to use :GetSortedAsync until entries start returning nil.
Hey @Snow_Lober!
Like what @7z99 said, no there is not.
However a much faster option is to increment a seperate datastore value every time an article is added to the ordered datastore you’d like to view the length of.
For example, if it were a “longest time played” global leaderboard, when a new player joins you would add their time to the ordered datastore, and then in a separate datastore under the same key as everyone else simple get the value and set it to itself plus 1. When removing these values from your ordered datastore you would simply decrement that separate value by one.
This would allow you to always have the correct length of your ordered datastore, although you would need to dynamically get that value every time you needed it, as it could change throughout gameplay.
Hope this helped!
I don’t recommend doing this for a few reasons:
1- it’s creating an extra :IncrementAsync request
2- If it fails even once, it’s going to be inaccurate
3- It’s asynchronous so it won’t increment properly if two people join at the same time
Oh those are really good points!
But you have to agree that iterating through every page of an ordered datastore is way inefficient.
My final solution is that the server could automatically check the length of the ordered datastore every few minutes or however long, and then set a separate datastore with the value of its length.
This carries the same failure issue, but considering it’s once per few minutes it’ll likely never fail, and even if it does it’ll get the correct value in just a few more minutes.