From fcd13c9a7195338ec6374cf5ac243ace7a93dd7f Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Tue, 26 Feb 2013 01:55:25 +0530 Subject: [PATCH] (Bug 45372) COMMIT to the database at lesser intervals --- .../ContributionsSyncAdapter.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/commons/src/main/java/org/wikimedia/commons/contributions/ContributionsSyncAdapter.java b/commons/src/main/java/org/wikimedia/commons/contributions/ContributionsSyncAdapter.java index e7b4414ea..ec133e3db 100644 --- a/commons/src/main/java/org/wikimedia/commons/contributions/ContributionsSyncAdapter.java +++ b/commons/src/main/java/org/wikimedia/commons/contributions/ContributionsSyncAdapter.java @@ -18,6 +18,7 @@ import java.util.Date; import java.util.List; public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter { + private static int COMMIT_THRESHOLD = 10; public ContributionsSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); } @@ -89,12 +90,23 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter { Contribution contrib = new Contribution(null, thumbUrl, filename, "", -1, dateUpdated, dateUpdated, user, ""); contrib.setState(Contribution.STATE_COMPLETED); imageValues.add(contrib.toContentValues()); + + if(imageValues.size() % COMMIT_THRESHOLD == 0) { + try { + contentProviderClient.bulkInsert(ContributionsContentProvider.BASE_URI, imageValues.toArray(new ContentValues[]{})); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + imageValues.clear(); + } } - try { - contentProviderClient.bulkInsert(ContributionsContentProvider.BASE_URI, imageValues.toArray(new ContentValues[]{})); - } catch (RemoteException e) { - throw new RuntimeException(e); + if(imageValues.size() != 0) { + try { + contentProviderClient.bulkInsert(ContributionsContentProvider.BASE_URI, imageValues.toArray(new ContentValues[]{})); + } catch (RemoteException e) { + throw new RuntimeException(e); + } } queryContinue = result.getString("/api/query-continue/logevents/@lestart"); if(TextUtils.isEmpty(queryContinue)) {