#datastore key character limit of 50 is cooking me

1 messages · Page 1 of 1 (latest)

terse compass
#

guys i have a unique problem. i have an ODS where entries use a group of player's userids as the key (with / seperator) and the time it took for them to complete something as the data. this is so I can use ODS:GetSortedAsync() and get the data sorted by fastest completions, while retaining their user info.

BUT i just found out keys have 50-character limit and userids can be up to 10 digits, so

6 max players * 10 digits = 60 characters > 50 limit>

so WHAT do I do bro? i might be braindead btw 💔

thorn hemlock
#

keys should be used as an index, not a data storage medium

terse compass
#

so i thought using the concatenation of their userids as the key was fair

#

but i implemented a base change to make the numbers smaller 👍

#

so ig it's fixed

thorn hemlock
#

it's an extra step but not far out of the way

terse compass
thorn hemlock
#

'fastest time' for what

thorn hemlock
#

The XY problem is asking about your attempted solution rather than your actual problem. This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

User wants to do X.
User doesn't know how to do X, but thinks they can fumble their way to a solution if they can just manage to do Y.
User doesn't know how to do Y either.
User asks for help with Y.
Others try to help user with Y, but are confused because Y seems like a strange problem to want to solve.
After much interaction and wasted time, it finally becomes clear that the user really wants help with X, and that Y wasn't even a suitable solution for X.
The problem occurs when people get stuck on what they believe is the solution and are unable step back and explain the issue in full.

terse compass
#

so i have this game that people can complete in an amount of time

#

all im trying to do is store the time it took for a group to complete the game

thorn hemlock
terse compass
thorn hemlock
#

so what you're actually trying to show is the fastest completion alongside the people who participated in that run?

terse compass
#

exactly yes

thorn hemlock
#

there being no correlation between the specific people, its just whoever showed up at the time

terse compass
#

and be able to retrieve that data by the time it took them, ascending

thorn hemlock
#

okay ya theres probably an easier way to do that

terse compass
thorn hemlock
#

what about for individual players? do they need to be able to see their times?

#

or is it purely leaderboard?

terse compass
#

it's just for leaderboard yeah

thorn hemlock
#

okay so first thing i'd do is assert all completed runs are unique

#

I suggest using GlobalDataStore and incrementasync on the same key for all servers to get the next unique index, alternatively you can use httpservice:generateguid

#

since guid's are practically guaranteed to be unique (in theory there is tiny chance for duplicates to appear, but it's so vanishingly unlikely that it is assumed to never happen)

#

now that you have a unique id for each run, you would store the time value in an ordered datastore, and the userids/metadata/etc in a regular datastore, both on the same unique id key generated in the first step

#

so with that set up you can do orderedstore:getsortedasync() for ordered key-time pairs, and then to get the player list you do a second query to the regular datastore for each key in the key-time pairs to get the userids associated with that key

#

that's roughly how i would do it

#

i suggest also considering using memoryhashmap for userids + memorysortedmap for times instead of datastore + orderedstore so that entries delete after 45 days (max) if you wanted the leaderboard to only record the past month or so

thorn hemlock
terse compass
#

damn it really was an xy problem after all 😔

#

thanks for the explanation

thorn hemlock
#

do be mindful that something like that is going to use a lot of datastore quota because each row from the orderedstore must be paired with another datastore query

#

so it may take a while for the leaderboard to load more than the first 20

#

you'd use the time as the sortkey, and the value is a string containing comma separated userids

#

so it's easier if you're fine with temporary scores because of that, or if you really want permanent you'll probably have to do the first method