Odoo-mobile / framework

Odoo Mobile Framework
https://play.google.com/store/apps/dev?id=8607973775002477408
Other
327 stars 374 forks source link

How to sync a huge table in batches to prevent OOM errors #319

Open warp10 opened 7 years ago

warp10 commented 7 years ago

I need to sync a huge database table from Odoo (it contains a binary field with a lot of data), and unfortunately we need to sync it all at once, as we must have the data available on the device for offline use.

Now, our problem is that we get an OOM error when we try to sync the table from Odoo to Android, and I suppose it is related to the size of the table itself. I read an interesting hint by @dpr-odoo on Issue #216, that is using syncDataLimit() to limit the amount of data synced, so to prevent the OOM error. My question is: how can I reiterate the sync in batches until the whole table is properly synced?

adam-nadar commented 7 years ago

try using ir.attachment to download huge binary data referencing it..... so get the binary data when it is needed and update the record with background service..

kasim1011 commented 7 years ago

@warp10 Hello, you can always register receiver for ISyncFinishReceiver.SYNC_FINISH on OnResume(). after you do this when you start sync for any model the iSyncFinishReceiver->onReceive() will call when syncing get finish for that model. so, you can start syncing for next model.

private ISyncFinishReceiver iSyncFinishReceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    iSyncFinishReceiver = new ISyncFinishReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
              // previous model sync done. request for next model sync.....
        }
}

@Override
protected void onResume() {
    super.onResume();
    this.registerReceiver(iSyncFinishReceiver,
            new IntentFilter(ISyncFinishReceiver.SYNC_FINISH));
}

@Override
protected void onPause() {
    super.onPause();
    try {
        this.unregisterReceiver(iSyncFinishReceiver);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
mikedream89 commented 6 years ago

@warp10 Do you fix about sync a huge database table?

warp10 commented 6 years ago

@mikedream89 Not yet. The suggestion from kasim1011 doesn't really apply to our case, as we don't have any issue in starting another model after the current one, we have problems syncing one big, specific model. We worked around that limiting the number of items synced at each sync, but that's not a actual solution