Idea

Daxay avatar image
Daxay suggested

Return old data on update user data call

It would be great if we can have this feature.

It would be useful in preventing concurrency.

For example, I have one claimDailyRewards cloudscript function which gives reward to user in their inventory.

I want to give user reward only 1 time during day, so for that i am using DAILY_REWARD_STATS key for storing daily timer details and no of day.


Here the main problem is if two concurrent request from same user come then there are high chances that both request add rewards to user.
I am using below code. As you can see i am updating readonly data as soon as current data validation completed.

const combinedData = server.GetPlayerCombinedInfo({
  PlayFabId: currentPlayerId,
  InfoRequestParameters: {
      GetUserReadOnlyData: true,
      UserReadOnlyDataKeys: [UserReadonlyDataKeys.DAILY_REWARD_STATS],
      GetUserVirtualCurrency: true,
  },
}).InfoResultPayload;
const userReadonlyData = combinedData.UserReadOnlyData;
const userBalance = combinedData.UserVirtualCurrency;

if (!userReadonlyData[UserReadonlyDataKeys.DAILY_REWARD_STATS]) {
  throw new Error('You are not yet eligible to claim reward');
}
server.UpdateUserReadOnlyData({
  PlayFabId: currentPlayerId,
  KeysToRemove: [UserReadonlyDataKeys.DAILY_REWARD_STATS],
});

Stills it won't be enough to prevent concurrent requests.

But using this feature we can prevent concurrent requests.

Player DataCloudScriptdata
10 |1200

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

No Comments

·

Write a Comment

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

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.