Hello,
I have 2 approaches about reading/writing data in Cloudscript in this kind of cases. Which one will be more efficient in terms of billing?
1)
// ... checking if 'args' are sent correctly var getData = { "PlayFabId": currentPlayerId, "Keys": ["Key1", "Key2", "Key3", "Key4", "Key5", "Key6"] }; var result = server.GetUserData(getData); if(result.Data["Key1"] != null) { // ... do something if(result.Data["Key2"] != null && parseInt(result.Data["Key2"].Value) == 1) { return 0; } } if(parseInt(args.Result) == 0) { var value1 = result.Data["Key3"].Value; var value2 = result.Data["Key4"].Value; // ... do something } else { var value1 = result.Data["Key5"].Value; var value2 = result.Data["Key6"].Value; // ... do something }
In the code above, I read all 6 keys at one time. I don't use some of them, but just in case, I read all of them at the beginning. Basically, 1 GetUserData call and 6 key-value pairs read.
2)
// ... checking if 'args' are sent correctly var getData1 = { "PlayFabId": currentPlayerId, "Keys": ["Key1"] }; var result1 = server.GetUserData(getData1); if(result1.Data["Key1"] != null) { // ... do something var getData2 = { "PlayFabId": currentPlayerId, "Keys": ["Key2"] }; var result2 = server.GetUserData(getData2); if(result2.Data["Key2"] != null && parseInt(result2.Data["Key2"].Value) == 1) { return 0; } } if(parseInt(args.Result) == 0) { var getData3 = { "PlayFabId": currentPlayerId, "Keys": ["Key3", "Key4"] }; var result3 = server.GetUserData(getData3); var value1 = result3.Data["Key3"].Value; var value2 = result3.Data["Key4"].Value; // ... do something } else { var getData3 = { "PlayFabId": currentPlayerId, "Keys": ["Key5", "Key6"] }; var result3 = server.GetUserData(getData3); var value1 = result3.Data["Key5"].Value; var value2 = result3.Data["Key6"].Value; // ... do something }
In this code, I read the keys when they are needed. The worst case is 3 GetUserData call and 4 key-value pairs read. The best case is 2 GetUserData call and 2 key-value pairs read.
Which approach should I use? The first approach looks like spinning read/write meter unnecessarily, so the second approach looks more appropriate, but I wonder if calling GetUserData function has any affect on billing too?