question

mwillows avatar image
mwillows asked

Querying user data using a group from leaderboards and running in to API limits

We're building out an asynchronous PVP system in which a player can attack another player of a similar power range. So I've set up a system in which our game has a leaderboard that tracks a player's power. This works great. I have a Cloudscript call "GetOpponent()", which gets the nearest 20 players around the player and returns one randomly to attack. This also works great.

However there's some additional limitiations that I'm trying to add to the system. An attack time limit and a basic building requirement, i.e. only allow valid opponents who haven't been attacked in the last 5 minutes or so, and only allow opponents who have a minimum number of buildings to attack. In order to track this data I have a simple json blob, combatInfo, stored in in the playerData for a given player. combatInfo has a lastAttackedTime property, and a buildingCount property that get updated when a player is attacked and when their buildings get modified.

This also all works fine.

But the problem is that in order sort the possible opponents I need to call a GetUserTitleData on each one. Theres a few other API calls as well, for instance the minimum time until attacked again is stored in title data. Basically, my problem is that I'm running in to the cloudscript API call limit as soon as I get more than 3 or 4 opponents, and even if I manage to optimize the required calls perfectly I calculate the most I could do would be basically 10 possible opponents which will not really give us the range we need. My other option is to move this to the client and pass the client the list of possible opponents and then have the client query them in order to find a valid opponent, but this seems even more inefficent as now I have additional queries coming from the client and I'd prefer to keep the entire call on the server. Another option (which I'm trying to avoid) is a custom server as otherwise working with the cloudscript is great.

Finally would porting my scripts to functions impact these limits, seems like there's no API call limits there? Although non-trivial, we do plan to port everything to functions eventually regardless.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

In the case of choosing opponents from 20 players, if I understand it correctly, you are trying to iterate all 20 players and find all possible opponents, meaning that you'll need to call GetUserData (I believe you are referring to this API instead of GetUserTitleData) 20 times, is that correct? Is it a must that all possible opponents need to be found? If not, as I see it, you can just find the first player who meets the criteria instead of iterating all the players using some kind of a mechanism, for instance, starting from the 1st player above, and then the 1st player below, then the 2nd above... This could potentially cut down API calls, how does that sound?

However, as the number of players you want to choose from increases, let's say 50 players, and, you probably will also want to add more logics into the system. All these factors could potentially increase the number of API calls and execution time to some point where there is no enough room for optimization. Therefore, as I see it, porting to functions sounds like a more sustainable choice.

I can see that you also submitted a support ticket for this, please keep in touch with that channel to get more dedicated support:)

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jordan avatar image Jordan ♦ commented ·

Both suggestions will prove valuable- a lower sample size and more logic in Functions. For now, since it is not required to display the opponent information, you can pick and test a few opponents at a time.

And as you scale, Functions will prove to be powerful, especially in regards to the way your title is structured.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.