8 Mar 2013 12:54 AM #1
Unanswered: Best Practice for App Updates / Offline handling
I want to improve the performance of my app. My app fetches JSONP data from my server. My question now is how is the best practice for doing data updates and saving data for offline mode?
My current workflow was the following:
- Fetch data from JSONP-Api if device is online
- Sync it to an localStorage-Store
- set an timestamp for last data update
- on next store.load() check if a defined time interval has passed since the last update
Are there any improvements or better logic I can implement to do data updates?
How can I send only changed data from the server, and replace/update it in the app?
In my current app project I have different stores:
- assetdata (link to attached images/pdfs)
By now I have a JSONP proxy for each store. Could i reach a better performance if the server would send a nested json which holds the data of all stores by doing only one http request than three?
8 Mar 2013 6:09 AM #2
I have loads of experience in this kind of thing, but really the solution depends on what kind of data you're handling... is it user specific or just generic content that gets updated on the server? What are the sizes of the stores involved? Are you deploying as native or webapp (or both?!) Would be happy to advise based on your individual situation.
8 Mar 2013 6:39 AM #3
shepsii thanks for your help!
At this time I'm loading data from an product information system (mysql database). My three stores all have max 500-600 records, but this will increase soon (many thousands expected) . At this point the largest JSON-File is about 74kB. And I load each of the stores in a single JSONP-Request. Maybe in the future there are client specific data, but for now it comes from the same database.
I have the following app structure:
- show a list with categories (nested in n levels, each category has a parent_id ) ~ 500 records
- navigate through categorie tree / by filtering the list by the parent_id / id of the category which has been clicked (maybe this is worse? is there a better solution?)
- at the end of the tree I show a detail panel of a product which is related to a category
- a product has keys related data to an asset store (linked PDFs, Images, text files etc.)
So you see i have three stores which are related to each other connected via primary keys (ids).
If I show the detail panel for a product I filter the other Stores to collect the data I need to display. With 500-600 records I don't have performance issues but I have to improve it when the number grows. And I think my approach by filtering the Stores (e.g. filter asset store for images related to product #5 with a regexp of the id).
Just because of the fact, that i want to display and download PDFs I deploy the app to native via Phonegap.
I really appreciate your help :-)
8 Mar 2013 7:04 AM #4
To get around potential issues with your filter system, and to be able to deal with larger data sets, given you're going to native I would suggest using a sqlite plugin with phonegap eg, https://github.com/brodyspark/PhoneG...Plugin-Android, there is one for ios too. You can test locally using websql - the queries will remain the same, you'll just need to change the line in your code that opens the database.
The filtering will be fixed because a sqlite proxy will only fetch the records it needs if you use remoteFilter. I don't know if the sencha proxy does this - I haven't personally looked into it - but the one I wrote would.
If the thought of plugins to phonegap scare you (they did me at first!) and you're confident your data sets won't go past 5mb, you can just use websql. the sqlite sencha touch proxies will still work the same.
Apple are very pernickity about where you put data inside an app. They hate it when a new app is downloaded and instantly data is put into icloud. You can get away with this if the data is all client-specific, but if it's just generic content they really hate this getting into icloud. You'll need to make sure that the metadata on the sqlite db file is set appropriately.
Another method I use is to write data in JSON format to files using phonegap's read/write tools. The reason I like this is that you can be fairly consistent in testing as there's just some updating code that you need to test natively, and everything else is the same.
The disadvantage here is you have to read the whole JSON file into memory every time you want to do anything.
I've found that only giving data to Sencha Touch stores when they MUST have it for display, massively increases performance. There is nothing that kills the performance of a Sencha Touch app more than having a view that isn't currently active, that contains a dataview/list attached to a store, which is then manipulated, as ST will go update the DOM of the inactive view, iterating through the Ext.XTemplate for each affected record, adding new listeners for new records etc, and the amount of memory and processing this eats up is ugly. So that's why I'd use a sqlite proxy that only reads in the data from the database as and when you need it for display.
14 Mar 2013 12:29 AM #5
Hi thanks for your answer, this really helps me!!!
Of course I will use a database as you suggested. I would never have the idea to use a database because my scope was only sencha touch. But as you said I can use Phonegap plugins to achieve this.
If I come to the point where I want to display data I would fetch the data from the DB and put it in a temporary store (which is bound to the list) ?
Then I would set up an sqlite database, and to update my data I would send data from the server via JSONP and update the database records which have been changed.
Have you some improvements (server side) which I can implement to minimize mobile traffic? I don't want to send all data, but only new/changed data.