JSON store hangs while retrieving data

139 views Asked by At

We have observed that at certain times accessing the JSONStore API's hangs for long time, to make it work we have to call the function again or app has to be taken to background & bring to foreground again.

NOTE : when application faces this issue, behaviour is same until we reinstall the app or reboot the device.

There doesn't appear to be any proper scenarios for this, we have searched many articles but did not find any solution, any solutions are welcome.

We observed this issue on Android devices like S5 and S4.

Here is my code Snippet:

function getWidgets(w_id, getWidgetsSuccessCallback, getWidgetsFailureCallback) {

var query = { user_id : w_id };
var options = {};

WL.JSONStore.get(StorageCollections.widgets).find(query, options)
.then(function(arrayResults) {
    var count = arrayResults.length;

    Logger.debug("getWidgets: success, count: " + count);

    ...

    getWidgetsSuccessCallback(widgets);
})
.fail(function(errorObject) {
    Logger.error("getWidgets: failed, error: " + JSON.stringify(errorObject));
    getWidgetsFailureCallback(errorObject);
});}

Logs when everything works fine http://pastebin.com/NVP8ycTG

Logs when accessing JSON store hangs, it will work only when app taken to background & bring back to foreground again http://pastebin.com/eYzx57qC

JSON store is initialised as below

var collections = {
// User
user: {
    searchFields: {
        user_id             : 'string',
        user_name           : 'string',
        first_name          : 'string',
        last_name           : 'string',
    }           
}
}};


// Storage encryption
var options = {};
if (key) {
    options.password = key;
    options.localKeyGen = true;
}

// Open the collection
var promise = WL.JSONStore.init(collections, options)
.then(function() {
    Logger.debug("initializeAppStorage: " + JSON.stringify(collections) + " completed");
    initAppStorageSuccessCallback(true);
    return true;
})
// Handle failure
.fail(function(errorObject) {
    Logger.error("initializeAppStorage: failed, error: " + errorObject.toString());
    initAppStorageFailureCallback(errorObject.toString());
    return false;
});
return promise;

Thanks.

1

There are 1 answers

1
Mohammad Ashfaq On

Try this one :

function getWidgets(w_id, getWidgetsSuccessCallback, getWidgetsFailureCallback) {

var query = { key : w_id };
var options = {};

WL.JSONStore.get(StorageCollections.widgets).find(query, options)
.then(function(arrayResults) {
    var count = arrayResults.length;

    Logger.debug("getWidgets: success, count: " + count);

    ...

    getWidgetsSuccessCallback(widgets);
})
.fail(function(errorObject) {
    Logger.error("getWidgets: failed, error: " + JSON.stringify(errorObject));
    getWidgetsFailureCallback(errorObject);
});}