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
diff --git a/src/com/android/providers/calendar/CalendarDatabaseHelper.java b/src/com/android/providers/calendar/CalendarDatabaseHelper.java
index d609bdf..db70269 100644
--- a/src/com/android/providers/calendar/CalendarDatabaseHelper.java
+++ b/src/com/android/providers/calendar/CalendarDatabaseHelper.java
@@ -1512,7 +1512,11 @@
* 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/') "
@@ -1520,6 +1524,7 @@
+ "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'");