From 03a83f5341083f5866f05ed37e437c968fdeb2c1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 25 Sep 2020 14:39:34 +0200 Subject: [PATCH] delete invalid DB files in batches, not one by one --- .../gallery/pro/activities/MainActivity.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 3de7e5fb3..b21fbca6e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -970,14 +970,19 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { }.start() } - getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { - it.forEach { - if (!curMedia.contains(it)) { - val path = (it as? Medium)?.path - if (path != null) { - deleteDBPath(path) + if (!directory.isRecycleBin()) { + getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { + val mediaToDelete = ArrayList() + it.forEach { + if (!curMedia.contains(it)) { + val medium = it as? Medium + val path = medium?.path + if (path != null) { + mediaToDelete.add(medium) + } } } + mediaDB.deleteMedia(*mediaToDelete.toTypedArray()) } } }