summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Jang <wjang@google.com>2015-07-27 18:18:39 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-07-27 18:18:39 +0000
commit857df2e95a30e27642bd31f58e8760f790e699c8 (patch)
treef27073f02f5cf807f803c153cdd8eb329bf4873b
parent262b6fd102bb8db60ec0258c3ecc8fad72b3e872 (diff)
parent07d1a77c4298558c3c4c4f6672d3c31418bd4deb (diff)
downloadpackages_apps_Contacts-857df2e95a30e27642bd31f58e8760f790e699c8.tar.gz
packages_apps_Contacts-857df2e95a30e27642bd31f58e8760f790e699c8.tar.bz2
packages_apps_Contacts-857df2e95a30e27642bd31f58e8760f790e699c8.zip
am 07d1a77c: am 0653de3d: Apply contact join ops before we reach the max batch op threshold
* commit '07d1a77c4298558c3c4c4f6672d3c31418bd4deb': Apply contact join ops before we reach the max batch op threshold
-rw-r--r--src/com/android/contacts/ContactSaveService.java26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/com/android/contacts/ContactSaveService.java b/src/com/android/contacts/ContactSaveService.java
index 9944c77c6..dc6cdebbb 100644
--- a/src/com/android/contacts/ContactSaveService.java
+++ b/src/com/android/contacts/ContactSaveService.java
@@ -142,6 +142,8 @@ public class ContactSaveService extends IntentService {
private static final int PERSIST_TRIES = 3;
+ private static final int MAX_CONTACTS_PROVIDER_BATCH_SIZE = 499;
+
public interface Listener {
public void onServiceCompleted(Intent callbackIntent);
}
@@ -1078,23 +1080,39 @@ public class ContactSaveService extends IntentService {
// For each pair of raw contacts, insert an aggregation exception
final ContentResolver resolver = getContentResolver();
- final ArrayList<ContentProviderOperation> operations
- = new ArrayList<ContentProviderOperation>();
+ // The maximum number of operations per batch (aka yield point) is 500. See b/22480225
+ final int batchSize = MAX_CONTACTS_PROVIDER_BATCH_SIZE;
+ final ArrayList<ContentProviderOperation> operations = new ArrayList<>(batchSize);
for (int i = 0; i < rawContactIds.length; i++) {
for (int j = 0; j < rawContactIds.length; j++) {
if (i != j) {
buildJoinContactDiff(operations, rawContactIds[i], rawContactIds[j]);
}
+ // Before we get to 500 we need to flush the operations list
+ if (operations.size() > 0 && operations.size() % batchSize == 0) {
+ if (!applyJoinOperations(resolver, operations)) {
+ return;
+ }
+ operations.clear();
+ }
}
}
+ if (operations.size() > 0 && !applyJoinOperations(resolver, operations)) {
+ return;
+ }
+ showToast(R.string.contactsJoinedMessage);
+ }
- // Apply all aggregation exceptions as one batch
+ /** Returns true if the batch was successfully applied and false otherwise. */
+ private boolean applyJoinOperations(ContentResolver resolver,
+ ArrayList<ContentProviderOperation> operations) {
try {
resolver.applyBatch(ContactsContract.AUTHORITY, operations);
- showToast(R.string.contactsJoinedMessage);
+ return true;
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, "Failed to apply aggregation exception batch", e);
showToast(R.string.contactSavedErrorToast);
+ return false;
}
}