mirror of
https://github.com/etesync/android
synced 2025-07-01 12:22:38 +00:00
Don't load all resources when syncing, only as needed.
This commit is contained in:
parent
8040ee7d9f
commit
d6864f5062
@ -18,6 +18,7 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.provider.CalendarContract;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.ContactsContract.Groups;
|
import android.provider.ContactsContract.Groups;
|
||||||
import android.provider.ContactsContract.RawContacts;
|
import android.provider.ContactsContract.RawContacts;
|
||||||
@ -30,6 +31,7 @@ import java.util.List;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import at.bitfire.davdroid.App;
|
import at.bitfire.davdroid.App;
|
||||||
|
import at.bitfire.ical4android.CalendarStorageException;
|
||||||
import at.bitfire.vcard4android.AndroidAddressBook;
|
import at.bitfire.vcard4android.AndroidAddressBook;
|
||||||
import at.bitfire.vcard4android.AndroidContact;
|
import at.bitfire.vcard4android.AndroidContact;
|
||||||
import at.bitfire.vcard4android.AndroidGroup;
|
import at.bitfire.vcard4android.AndroidGroup;
|
||||||
@ -149,6 +151,15 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
|||||||
return nameless.toArray(new LocalResource[nameless.size()]);
|
return nameless.toArray(new LocalResource[nameless.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalResource getByUid(String uid) throws ContactsStorageException {
|
||||||
|
LocalContact[] ret = (LocalContact[]) queryContacts(AndroidContact.COLUMN_FILENAME + " =? ", new String[]{uid});
|
||||||
|
if (ret != null && ret.length > 0) {
|
||||||
|
return ret[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteAll() throws ContactsStorageException {
|
public void deleteAll() throws ContactsStorageException {
|
||||||
try {
|
try {
|
||||||
provider.delete(syncAdapterURI(RawContacts.CONTENT_URI), null, null);
|
provider.delete(syncAdapterURI(RawContacts.CONTENT_URI), null, null);
|
||||||
|
@ -125,6 +125,15 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
|||||||
return (LocalEvent[])queryEvents(Events._SYNC_ID + " IS NULL AND " + Events.ORIGINAL_ID + " IS NULL", null);
|
return (LocalEvent[])queryEvents(Events._SYNC_ID + " IS NULL AND " + Events.ORIGINAL_ID + " IS NULL", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalEvent getByUid(String uid) throws CalendarStorageException {
|
||||||
|
LocalEvent[] ret = (LocalEvent[]) queryEvents(Events._SYNC_ID + " =? ", new String[]{uid});
|
||||||
|
if (ret != null && ret.length > 0) {
|
||||||
|
return ret[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalResource[] getDirty() throws CalendarStorageException, FileNotFoundException {
|
public LocalResource[] getDirty() throws CalendarStorageException, FileNotFoundException {
|
||||||
List<LocalResource> dirty = new LinkedList<>();
|
List<LocalResource> dirty = new LinkedList<>();
|
||||||
|
@ -21,6 +21,7 @@ public interface LocalCollection {
|
|||||||
LocalResource[] getDirty() throws CalendarStorageException, ContactsStorageException, FileNotFoundException;
|
LocalResource[] getDirty() throws CalendarStorageException, ContactsStorageException, FileNotFoundException;
|
||||||
|
|
||||||
LocalResource[] getAll() throws CalendarStorageException, ContactsStorageException;
|
LocalResource[] getAll() throws CalendarStorageException, ContactsStorageException;
|
||||||
|
LocalResource getByUid(String uid) throws CalendarStorageException, ContactsStorageException;
|
||||||
|
|
||||||
String getCTag() throws CalendarStorageException, ContactsStorageException;
|
String getCTag() throws CalendarStorageException, ContactsStorageException;
|
||||||
void setCTag(String cTag) throws CalendarStorageException, ContactsStorageException;
|
void setCTag(String cTag) throws CalendarStorageException, ContactsStorageException;
|
||||||
|
@ -17,6 +17,7 @@ import android.database.Cursor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.provider.CalendarContract;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import org.dmfs.provider.tasks.TaskContract.TaskLists;
|
import org.dmfs.provider.tasks.TaskContract.TaskLists;
|
||||||
@ -93,6 +94,15 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
|
|||||||
return (LocalTask[])queryTasks(Tasks._SYNC_ID + " IS NULL", null);
|
return (LocalTask[])queryTasks(Tasks._SYNC_ID + " IS NULL", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalTask getByUid(String uid) throws CalendarStorageException {
|
||||||
|
LocalTask[] ret = (LocalTask[]) queryTasks(Tasks._SYNC_ID + " =? ", new String[]{uid});
|
||||||
|
if (ret != null && ret.length > 0) {
|
||||||
|
return ret[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalResource[] getDirty() throws CalendarStorageException, FileNotFoundException {
|
public LocalResource[] getDirty() throws CalendarStorageException, FileNotFoundException {
|
||||||
LocalTask[] tasks = (LocalTask[])queryTasks(Tasks._DIRTY + "!=0 AND " + Tasks._DELETED + "== 0", null);
|
LocalTask[] tasks = (LocalTask[])queryTasks(Tasks._DIRTY + "!=0 AND " + Tasks._DELETED + "== 0", null);
|
||||||
|
@ -96,25 +96,18 @@ public class CalendarSyncManager extends SyncManager {
|
|||||||
App.log.warning("Received multiple VCALs, using first one");
|
App.log.warning("Received multiple VCALs, using first one");
|
||||||
|
|
||||||
Event event = events[0];
|
Event event = events[0];
|
||||||
|
LocalEvent local = (LocalEvent) localCollection.getByUid(event.uid);
|
||||||
|
|
||||||
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
||||||
LocalResource local = processEvent(event);
|
processEvent(event, local);
|
||||||
|
|
||||||
if (local != null) {
|
|
||||||
localResources.put(local.getUuid(), local);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LocalResource local = localResources.get(event.uid);
|
|
||||||
App.log.info("Removing local record #" + local.getId() + " which has been deleted on the server");
|
App.log.info("Removing local record #" + local.getId() + " which has been deleted on the server");
|
||||||
localResources.remove(local.getUuid());
|
|
||||||
local.delete();
|
local.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalResource processEvent(final Event newData) throws IOException, ContactsStorageException, CalendarStorageException {
|
private LocalResource processEvent(final Event newData, LocalEvent localEvent) throws IOException, ContactsStorageException, CalendarStorageException {
|
||||||
// delete local event, if it exists
|
// delete local event, if it exists
|
||||||
LocalEvent localEvent = (LocalEvent) localResources.get(newData.uid);
|
|
||||||
if (localEvent != null) {
|
if (localEvent != null) {
|
||||||
App.log.info("Updating " + newData.uid + " in local calendar");
|
App.log.info("Updating " + newData.uid + " in local calendar");
|
||||||
localEvent.setETag(newData.uid);
|
localEvent.setETag(newData.uid);
|
||||||
|
@ -149,26 +149,20 @@ public class ContactsSyncManager extends SyncManager {
|
|||||||
App.log.warning("Received multiple VCards, using first one");
|
App.log.warning("Received multiple VCards, using first one");
|
||||||
|
|
||||||
Contact contact = contacts[0];
|
Contact contact = contacts[0];
|
||||||
|
LocalResource local = (LocalResource) localCollection.getByUid(contact.uid);
|
||||||
|
|
||||||
|
|
||||||
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
||||||
LocalResource local = processContact(contact);
|
processContact(contact, local);
|
||||||
|
|
||||||
if (local != null) {
|
|
||||||
localResources.put(local.getUuid(), local);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LocalResource local = localResources.get(contact.uid);
|
|
||||||
App.log.info("Removing local record #" + local.getId() + " which has been deleted on the server");
|
App.log.info("Removing local record #" + local.getId() + " which has been deleted on the server");
|
||||||
localResources.remove(local.getUuid());
|
|
||||||
local.delete();
|
local.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalResource processContact(final Contact newData) throws IOException, ContactsStorageException {
|
private LocalResource processContact(final Contact newData, LocalResource local) throws IOException, ContactsStorageException {
|
||||||
String uuid = newData.uid;
|
String uuid = newData.uid;
|
||||||
// update local contact, if it exists
|
// update local contact, if it exists
|
||||||
LocalResource local = localResources.get(uuid);
|
|
||||||
if (local != null) {
|
if (local != null) {
|
||||||
App.log.log(Level.INFO, "Updating " + uuid + " in local address book", newData);
|
App.log.log(Level.INFO, "Updating " + uuid + " in local address book", newData);
|
||||||
|
|
||||||
|
@ -92,11 +92,6 @@ abstract public class SyncManager {
|
|||||||
*/
|
*/
|
||||||
protected List<JournalEntryManager.Entry> remoteEntries;
|
protected List<JournalEntryManager.Entry> remoteEntries;
|
||||||
|
|
||||||
/**
|
|
||||||
* sync-able resources in the local collection, as enumerated by {@link #prepareLocal()}
|
|
||||||
*/
|
|
||||||
protected Map<String, LocalResource> localResources;
|
|
||||||
|
|
||||||
public SyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, SyncResult syncResult, String uniqueCollectionId, CollectionInfo.Type serviceType) throws InvalidAccountException {
|
public SyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, SyncResult syncResult, String uniqueCollectionId, CollectionInfo.Type serviceType) throws InvalidAccountException {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
@ -311,19 +306,10 @@ abstract public class SyncManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all local resources which should be taken into account for synchronization into {@link #localResources}.
|
|
||||||
*/
|
*/
|
||||||
protected void prepareLocal() throws CalendarStorageException, ContactsStorageException {
|
protected void prepareLocal() throws CalendarStorageException, ContactsStorageException {
|
||||||
prepareDirty();
|
prepareDirty();
|
||||||
|
|
||||||
// fetch list of local contacts and build hash table to index file name
|
|
||||||
LocalResource[] localList = localCollection.getAll();
|
|
||||||
localResources = new HashMap<>(localList.length);
|
|
||||||
for (LocalResource resource : localList) {
|
|
||||||
App.log.fine("Found local resource: " + resource.getUuid());
|
|
||||||
localResources.put(resource.getUuid(), resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteCTag = localCollection.getCTag();
|
remoteCTag = localCollection.getCTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user