question

John Peterson avatar image
John Peterson asked

Server API: calling GrantUserItems versus ModifyItemUsesRequest.

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!

apisCloudScript
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

·
brendan avatar image
brendan answered

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:

  • The grant call will take about the same amount of work in either case (due to the pre-aggregation I mentioned).
  • Calls that operate on an item instance ID are extremely efficient, since that's their index in the table (no table scan required).

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.

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.

John Peterson avatar image John Peterson commented ·

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!

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.