Commit 63283da4 authored by Gorka Cañamaque's avatar Gorka Cañamaque Committed by Sébastien Toque

Improve database cleaning speed using a transaction

Signed-off-by: Sébastien Toque's avatarSébastien Toque <xilasz@gmail.com>
parent 9e72ac93
......@@ -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();
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment