[Android] Improve database cleaning speed using a transaction

Gorka Cañamaque git at videolan.org
Thu Jul 19 06:46:50 CEST 2012


android | branch: master | Gorka Cañamaque <gorka.canamaque at gmail.com> | Thu Jul 19 06:36:54 2012 +0200| [63283da423b4c6e81e84c56f3aac7291d577f6f0] | committer: Sébastien Toque

Improve database cleaning speed using a transaction

Signed-off-by: Sébastien Toque <xilasz at gmail.com>

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=63283da423b4c6e81e84c56f3aac7291d577f6f0
---

 vlc-android/src/org/videolan/vlc/DatabaseManager.java |   12 ++++++++++++
 vlc-android/src/org/videolan/vlc/MediaLibrary.java    |    4 +---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/DatabaseManager.java b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
index 7a55530..3f2abb3 100644
--- a/vlc-android/src/org/videolan/vlc/DatabaseManager.java
+++ b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Set;
 
 import android.content.ContentValues;
 import android.content.Context;
@@ -410,6 +411,17 @@ public class DatabaseManager {
         mDb.delete(MEDIA_TABLE_NAME, MEDIA_LOCATION + "=?", new String[] { location });
     }
 
+    public void removeMedias(Set<String> locations) {
+        mDb.beginTransaction();
+        try {
+            for (String location : locations)
+                mDb.delete(MEDIA_TABLE_NAME, MEDIA_LOCATION + "=?", new String[] { location });
+            mDb.setTransactionSuccessful();
+        } finally {
+            mDb.endTransaction();
+        }
+    }
+
     public synchronized void updateMedia(String location, mediaColumn col,
             Object object) {
         ContentValues values = new ContentValues();
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index d19dfea..680133b 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -264,9 +264,7 @@ public class MediaLibrary {
                 for (String fileURI : addedLocations) {
                     existingMedias.remove(fileURI);
                 }
-                for (String existingMedia : existingMedias.keySet()) {
-                    mDBManager.removeMedia(existingMedia);
-                }
+                mDBManager.removeMedias(existingMedias.keySet());
             }
 
             // hide progressbar in header



More information about the Android mailing list