mirror of
https://github.com/etesync/android
synced 2025-01-13 17:21:08 +00:00
Commit after every 100 resource downloads to avoid TransactionTooLargeException
This commit is contained in:
parent
d15478b863
commit
03a85da6e3
@ -22,9 +22,10 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.CalendarContract;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
//private static final String TAG = "davdroid.LocalCollection";
|
||||
private static final String TAG = "davdroid.LocalCollection";
|
||||
|
||||
protected Account account;
|
||||
protected ContentProviderClient providerClient;
|
||||
@ -126,7 +127,6 @@ public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
|
||||
public void updateByRemoteName(ResourceType remoteResource) throws RemoteException, ValidationException {
|
||||
ResourceType localResource = findByRemoteName(remoteResource.getName());
|
||||
|
||||
remoteResource.validate();
|
||||
|
||||
pendingOperations.add(
|
||||
@ -155,6 +155,8 @@ public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
}
|
||||
|
||||
public void commit() throws RemoteException, OperationApplicationException {
|
||||
Log.i(TAG, "Committing " + pendingOperations.size() + " operations");
|
||||
|
||||
if (!pendingOperations.isEmpty())
|
||||
providerClient.applyBatch(pendingOperations);
|
||||
|
||||
|
@ -11,7 +11,6 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.fortuna.ical4j.data.ParserException;
|
||||
import net.fortuna.ical4j.model.ValidationException;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
@ -22,14 +21,14 @@ import android.content.OperationApplicationException;
|
||||
import android.content.SyncResult;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import at.bitfire.davdroid.resource.IncapableResourceException;
|
||||
import at.bitfire.davdroid.resource.LocalCollection;
|
||||
import at.bitfire.davdroid.resource.RemoteCollection;
|
||||
import at.bitfire.davdroid.resource.Resource;
|
||||
import at.bitfire.davdroid.webdav.PreconditionFailedException;
|
||||
|
||||
public class SyncManager {
|
||||
private static String TAG = "davdroid.SyncManager";
|
||||
private static final String TAG = "davdroid.SyncManager";
|
||||
private static final int MAX_UPDATES_BEFORE_COMMIT = 100;
|
||||
|
||||
protected Account account;
|
||||
protected AccountManager accountManager;
|
||||
@ -134,7 +133,7 @@ public class SyncManager {
|
||||
|
||||
// PHASE 3: DOWNLOAD NEW/REMOTELY-CHANGED RESOURCES
|
||||
Log.i(TAG, "Adding " + resourcesToAdd.size() + " remote resource(s)");
|
||||
if (!resourcesToAdd.isEmpty())
|
||||
if (!resourcesToAdd.isEmpty()) {
|
||||
for (Resource res : dav.multiGet(resourcesToAdd.toArray(new Resource[0]))) {
|
||||
Log.i(TAG, "Adding " + res.getName());
|
||||
try {
|
||||
@ -142,20 +141,25 @@ public class SyncManager {
|
||||
} catch (ValidationException ex) {
|
||||
Log.w(TAG, "Ignoring invalid remote resource: " + res.getName(), ex);
|
||||
}
|
||||
syncResult.stats.numInserts++;
|
||||
|
||||
if (++syncResult.stats.numInserts % MAX_UPDATES_BEFORE_COMMIT == 0) // avoid TransactionTooLargeException
|
||||
local.commit();
|
||||
}
|
||||
local.commit();
|
||||
local.commit();
|
||||
}
|
||||
|
||||
Log.i(TAG, "Updating " + resourcesToUpdate.size() + " remote resource(s)");
|
||||
if (!resourcesToUpdate.isEmpty())
|
||||
for (Resource res : dav.multiGet(resourcesToUpdate.toArray(new Resource[0]))) {
|
||||
Log.i(TAG, "Updating " + res.getName());
|
||||
try {
|
||||
local.updateByRemoteName(res);
|
||||
} catch (ValidationException ex) {
|
||||
Log.e(TAG, "Ignoring invalid remote resource: " + res.getName(), ex);
|
||||
}
|
||||
Log.i(TAG, "Updating " + res.getName());
|
||||
syncResult.stats.numInserts++;
|
||||
|
||||
if (++syncResult.stats.numUpdates % MAX_UPDATES_BEFORE_COMMIT == 0) // avoid TransactionTooLargeException
|
||||
local.commit();
|
||||
}
|
||||
local.commit();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user