Enhance the performance of bulkInsert()
- Enclosed the method with DB transaction.
- Time to insert 4000 channels(seconds) : 92.151 -> 18.280
- reduced by 80%
BUG: 17961422, BUG: 16858261
Change-Id: I50fc367ad9b3e46b93563b37747bc386c257d7cf
diff --git a/src/com/android/providers/tv/TvProvider.java b/src/com/android/providers/tv/TvProvider.java
index 4ce8929..15cd9b8 100644
--- a/src/com/android/providers/tv/TvProvider.java
+++ b/src/com/android/providers/tv/TvProvider.java
@@ -814,6 +814,26 @@
}
}
+ @Override
+ public int bulkInsert(Uri uri, ContentValues[] values) {
+ setBatchNotificationsSet(Sets.<Uri>newHashSet());
+ Context context = getContext();
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ db.beginTransaction();
+ try {
+ int result = super.bulkInsert(uri, values);
+ db.setTransactionSuccessful();
+ return result;
+ } finally {
+ db.endTransaction();
+ final Set<Uri> notifications = getBatchNotificationsSet();
+ setBatchNotificationsSet(null);
+ for (final Uri uri : notifications) {
+ context.getContentResolver().notifyChange(uri, null);
+ }
+ }
+ }
+
private void notifyChange(Uri uri) {
final Set<Uri> batchNotifications = getBatchNotificationsSet();
if (batchNotifications != null) {