+ Start a Discussion
juhanajuhana 

Smartsync does not keep records

I am developing hybrid application with Backbone and Smartsync. For now, I'm using Event objects and only its standard fields. In online mode, Event object can be created to SF and read back. But if I go to offline, only some of the Event data's are stored locally. For example; online read return 19 objects but offline smartsql query returns 10. Does the StoreCache have size limit or something else or should it automatically store all data to cache when online query finishes ?

 

Event model fieldlist:

"WhoId", "WhatId", "StartDateTime", "EndDateTime", "Subject", "Id", "Description"

 Event Collection fieldlist is the same.

 

StoreCache for Events:

app.cache = new Force.StoreCache("events");
app.cacheForOriginals = new Force.StoreCache("original-events");
return $.when(app.cache.init(), app.cacheForOriginals.init());

Offline SmartSql query:

return {type:"cache", cacheQuery:{queryType:"smart", smartSql:"SELECT {events:_soup} FROM {events}"}};

 

I think this also somehow affects to creating Events locally. Allthough I can create Event locally save succeeds and pushing it to Event Collection from where I can render its data, refreshing (new fetch) Event Collection will lose newly created Event.

 

I'm little lost now, where I should look now ?

 

Kevin HawkinsKevin Hawkins

For SmartStore queries, the default page size is 10, which is likely why you're only getting back 10 items in the initial query.  You can up your page size as the most immediate workaround:

 

return {type:"cache", cacheQuery:{queryType:"smart", smartSql:"SELECT {events:_soup} FROM {events}", pageSize:20}};

 

juhanajuhana

Well, increasing pageSize did help but just a little.

 

If I put pageSize to 19, fetch returns all 19 objects what is in cache but if I set pageSize to 20, app will crash. So this value should not be changed ?

 

Also, how to loop pages what are returned. What I want is just retrieve all objects to collection model, online query does this just fine.

 

juhanajuhana

Ok, got more data on collection.

After fetch success, I check collection model hasMore() and use getMore() if data is available. Method getMore() returns result and also it automatically add objects to collection. Also, describeResults is inserted to collection, why that is there ?

 

But now; when I loop collection in and just print objects:

this.model.each(function(data){								console.log("data: "+JSON.stringify(data));
});

 First ones which have fetched with 'fetch' method print like this:

{"_soupEntryId":10,

 and the ones which came with getMore() print like this:

{"0":{"_soupEntryId":11,

 

Why this is happening ?