Permalink
Browse files

Speed up database update

Drop the trigger on sync_id before doing a bulk update of sync_id
fields.  This dramatically reduces the time required for the
calendar database update when there are lots of events.

Bug 5699796

Change-Id: I94c2fb624b5b63bfdf760b3092697f9205a634c9
  • Loading branch information...
1 parent 7c5e457 commit 3ac8148cdc79bde4b009ccb6a9ffda77bdb547d3 @fadden fadden committed Dec 3, 2011
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/com/android/providers/calendar/CalendarDatabaseHelper.java
@@ -1512,14 +1512,19 @@ void upgradeToVersion306(SQLiteDatabase db) {
* Change event id's from ".../private/full/... to .../events/...
* Set Calendars.canPartiallyUpdate to 1 to support partial updates
* Nuke sync state so we re-sync with a fresh etag and edit url
+ *
+ * We need to drop the original_sync_update trigger because it fires whenever the
+ * sync_id field is touched, and dramatically slows this operation.
*/
+ db.execSQL("DROP TRIGGER IF EXISTS original_sync_update");
db.execSQL("UPDATE Events SET "
+ "_sync_id = REPLACE(_sync_id, '/private/full/', '/events/'), "
+ "original_sync_id = REPLACE(original_sync_id, '/private/full/', '/events/') "
+ "WHERE _id IN (SELECT Events._id FROM Events "
+ "JOIN Calendars ON Events.calendar_id = Calendars._id "
+ "WHERE account_type = 'com.google')"
);
+ db.execSQL(CREATE_SYNC_ID_UPDATE_TRIGGER);
db.execSQL("UPDATE Calendars SET canPartiallyUpdate = 1 WHERE account_type = 'com.google'");

0 comments on commit 3ac8148

Please sign in to comment.