Dear PlayFab community,
If I am granting x50 of four different items in an operation, is it better to call GrantUserItems() one time with x200 ItemIds in the list, or call ModifyItemUsesRequest four times with the +50 increment? I feel like the former (GrantUserItems), largely to limit the number of Server API calls, but wanted to confirm.
Thanks in advance for any help anyone can provide!
Answer by Brendan · Oct 25, 2017 at 01:20 AM
Well first, it's important to realize that very large inventories and large inventory grants can take a significant amount of time to complete. Adding a bunch of a single stackable Item ID will be quick, since the items are pre-aggregated before the work to update the player inventory though, so given that you're referring to modifying the item uses, you shouldn't see issues with this (it's just good to bear that in mind).
Some details for the specific scenario you describe:
So it's actually fairly close, but for the extra Server API calls (which do increase the overall "cost" somewhat).
But the most important point is that by breaking the operation up into multiple calls, you're running the risk of the first call (or two or three) succeeding, but then the other calls failing due to the player losing connectivity. In that case, you're in a bad state. So I'd recommend making it one call to grant the items.
Thanks, Brendan! I think that helps me, and it's good to know that you pre-aggregate the ItemIDs from the GrantItemsToUser list.
I should have mentioned that, in my case, all these items are Stackable (but I think you assumed as much ;-).
Good point, too, that, from a data integrity perspective, it's better to reduce the number of API calls. To that end, I'll do as you suggest and go with the GrantItemsToUser.
Thanks again!
Add Hours/Minutes in Current Server Timestamp 1 Answer
Any way to "reset" all CloudScript instances? 1 Answer
Update Player Currency in Azure functions 1 Answer
How to access the variables of cloud scripts in Unity's C# script ? 0 Answers
Problem with CloudScript handler function returning string. 1 Answer