Hi,
I’d like some advice for how to structure my Storage Engine setup; I’m working on a fairly simple project that uses async battles against other (mostly) random opponents.
It’s made up of just 2 RPC functions; one to submit an entry, and one to get an entry for a specific stage.
// Request
itemVersion: string
stage: number
// Response
success: boolean
entry: any
- The
entry
is a Json object that has been submitted by a player. - Each player can submit multiple different entries, but should ideally not be able to be matched up against their own previous submissions.
- The outcome of the battle is handled locally, nothing will happen to the user who submitted the entry.
- I expect to cap the amount of entries to in the ballpark of 5-10.000 per stage, at which point I’ll start overwriting submissions.
- There’s currently a limit of 20 stages.
I’ve structured the collections like this:
collection: builds{itemVersion}-{stage}
key: new UUID v4
Currently I went the quick’n’dirty route and use a custom Sql query in order to get a random element:
let collection = `builds${msg.itemVersion}-${msg.stage}`
let query = 'SELECT collection, value FROM storage WHERE collection = $1 ORDER BY RANDOM() LIMIT 1'
let queryArgs = [collection]
let list = nk.sqlQuery(query, queryArgs)
This has worked fine for now, but I’d like to clean it up going forward.
I’m planning to extend the logic with:
- Bulk retrieval of entries for multiple stages
- Server-side filtering based on user id (aka don’t fetch your own submissions)
- Possibility for filtering on additional metadata (eg. score/ranking)
My thinking was to change the collection structure and then use storage indexing to query. However, I haven’t used indices before and am a bit unsure if this is the right way to go, so would appreciate some advice first
The most important hurdle is the bulk retrieval; I have a feeling that ~20 storage read requests across collections containing ~5000 entries would be quite a heavy operation?
–
Currently using Typescript with CockroachDB. Existing data does not have to be migrated.