From 43cc5c0e7bb9089916bbe1fafbf13677627ced1f Mon Sep 17 00:00:00 2001 From: rfc2822 Date: Mon, 6 Jan 2014 05:45:31 +0100 Subject: [PATCH] Commit after every full record insertion/update (closes #135) Docs say that TransactionTooLargeException is thrown when the buffer reaches 1 MB. Because we can't know how large a single insertion/update is and there may be contacts with larger photos, it's only safe to commit after every insertion/update. If photos exceed ~ 900 kB it would be required to write the photos to an asset file (maybe I'll do this later, then we can group insertions/updates again). --- .../davdroid/syncadapter/SyncManager.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/at/bitfire/davdroid/syncadapter/SyncManager.java b/src/at/bitfire/davdroid/syncadapter/SyncManager.java index 20a07b7e..4ec8e728 100644 --- a/src/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/src/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -174,14 +174,11 @@ public class SyncManager { Log.i(TAG, "Fetching " + resourcesToAdd.length + " new remote resource(s)"); for (Resource[] resources : ArrayUtils.partition(resourcesToAdd, MAX_MULTIGET_RESOURCES)) - try { - for (Resource res : remote.multiGet(resources)) { - Log.d(TAG, "Adding " + res.getName()); - local.add(res); - count++; - } - } finally { + for (Resource res : remote.multiGet(resources)) { + Log.d(TAG, "Adding " + res.getName()); + local.add(res); local.commit(); + count++; } return count; } @@ -191,14 +188,11 @@ public class SyncManager { Log.i(TAG, "Fetching " + resourcesToUpdate.length + " updated remote resource(s)"); for (Resource[] resources : ArrayUtils.partition(resourcesToUpdate, MAX_MULTIGET_RESOURCES)) - try { - for (Resource res : remote.multiGet(resources)) { - Log.i(TAG, "Updating " + res.getName()); - local.updateByRemoteName(res); - count++; - } - } finally { + for (Resource res : remote.multiGet(resources)) { + Log.i(TAG, "Updating " + res.getName()); + local.updateByRemoteName(res); local.commit(); + count++; } return count; }