mage / mage-sdk-unity

MAGE client SDK for Unity
MIT License
2 stars 13 forks source link

Issue with MGet (optional flag and cache) #56

Closed kefniark closed 7 years ago

kefniark commented 7 years ago

Description

Issue found with Archivist.MGet when using the flag optional = true in the current code, MGet crash on the first null element of the result and throw a nullReferenceException.

This happen because this element with a null value is not saved in the cache.

How to Test

In the following code, if any of the seasonId in queries doesn't exist in archivist, the MGet callback will return ("NullReferenceException", null)

var queries = new JObject();

foreach (var seasonId in seasonIds) {
    var rankingHistory = new JObject() {
        {"topic", new JValue(topicId)}, {
            "index", new JObject() { {"rankingId", new JValue(seasonId) } }
        }
    };

    // Creating Query
    queries.Add(seasonId, rankingHistory);
}

// Add Option: Optional
var options = new JObject();
options.Add("optional", new JValue(true));

Mage.Archivist.MGet(queries, options, callback);

Comment

ronkorving commented 7 years ago

Re. the JS implementation, if a value does not exist, it is cached with value undefined. So when doing a 2nd optional get, it will simply return that undefined and not hit the server again.

kefniark commented 7 years ago

After discussion, I changed a little bit this PR based on the JS Version:

Tested, it seems to properly work on our project

AlmirKadric commented 7 years ago

Completely my fault for not being more involved in the beginning. We fixed the problem in the wrong way. The issue is that when ValueDel is called we should be instantiating an empty VaultValue into the cache before null'ing it out. This is what ValueSet does. The delete logic is required as it throws other events that we need.

kefniark commented 7 years ago

ok let's restart another PR from scratch if it's to remove everything