Tom Counihan raised another issue with the current PBAP syncing in private email: if the phonebook download always takes too long, we never process the data and thus the cache forever remains out of sync. Tom proposed to download in smaller batches and import each batch separately. The problem with that approach is that we still need to get the entire address book from the phone before we can reliably determine deleted contacts. Let me offer a refinement of the original idea: instead of only processing a subset of the phone's contacts per sync, let's split the sync itself into more phases: * Start at offset x into the set of contacts. * Download n contacts and update the local database with them. * Update x persistently. * Repeat and role over until we have dealt with all contacts. * Then delete all local contacts which had no match on the phone anymore. In other words, we attempt to do a full sync each time we get triggered to do so, but it won't matter as much anymore when we get interrupted in the middle, because we will import new or updated contacts eventually. Deleting contacts will still depend on finishing the full download and processing. This batched download can be combined with checksuming by calculating a checksum over each batch. Finding a checksum depends on a few lookup keys: * start offset * batch size * with and without photo data We need to remove obsolete checksums to avoid growing their number infinitely. The batched download can be combined with incremental photo download by first downloading batches without photos, then with photos.