Check for dirty events in specified account before syncing

* We were starting a sync if there was a dirty event in ANY of
  our Exchange accounts
* Change to check for the specific account before syncing; this
  saves provider queries and service (i.e. thread) startups

Bug: 2550620
Change-Id: I83e953f1bade9fa269b777e96121a63664e8edc8
This commit is contained in:
Marc Blank 2010-03-27 10:51:10 -07:00
parent d682138090
commit 229666e106

View File

@ -43,6 +43,8 @@ public class CalendarSyncAdapterService extends Service {
private static final String ACCOUNT_AND_TYPE_CALENDAR = private static final String ACCOUNT_AND_TYPE_CALENDAR =
MailboxColumns.ACCOUNT_KEY + "=? AND " + MailboxColumns.TYPE + '=' + Mailbox.TYPE_CALENDAR; MailboxColumns.ACCOUNT_KEY + "=? AND " + MailboxColumns.TYPE + '=' + Mailbox.TYPE_CALENDAR;
private static final String DIRTY_IN_ACCOUNT =
Events._SYNC_DIRTY + "=1 AND " + Events._SYNC_ACCOUNT + "=?";
public CalendarSyncAdapterService() { public CalendarSyncAdapterService() {
super(); super();
@ -93,16 +95,13 @@ public class CalendarSyncAdapterService extends Service {
throws OperationCanceledException { throws OperationCanceledException {
ContentResolver cr = context.getContentResolver(); ContentResolver cr = context.getContentResolver();
boolean logging = Eas.USER_LOG; boolean logging = Eas.USER_LOG;
if (logging) {
Log.d(TAG, "performSync");
}
if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD)) { if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD)) {
Cursor c = cr.query(Events.CONTENT_URI, Cursor c = cr.query(Events.CONTENT_URI,
new String[] {Events._ID}, Events._SYNC_DIRTY + "=1", null, null); new String[] {Events._ID}, DIRTY_IN_ACCOUNT, new String[] {account.name}, null);
try { try {
if (!c.moveToFirst()) { if (!c.moveToFirst()) {
if (logging) { if (logging) {
Log.d(TAG, "Upload sync; no changes"); Log.d(TAG, "No changes for " + account.name);
} }
return; return;
} }
@ -125,7 +124,7 @@ public class CalendarSyncAdapterService extends Service {
try { try {
if (mailboxCursor.moveToFirst()) { if (mailboxCursor.moveToFirst()) {
if (logging) { if (logging) {
Log.d(TAG, "Calendar sync requested for " + account.name); Log.d(TAG, "Upload sync requested for " + account.name);
} }
// Ask for a sync from our sync manager // Ask for a sync from our sync manager
SyncManager.serviceRequest(mailboxCursor.getLong(0), SyncManager.serviceRequest(mailboxCursor.getLong(0),