add batch deleting of invalid files from room DB

This commit is contained in:
tibbi 2018-09-19 15:53:44 +02:00
parent ba732bd15a
commit 730ca8b5c0
2 changed files with 8 additions and 1 deletions

View file

@ -391,13 +391,16 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
callback(grouped.clone() as ArrayList<ThumbnailItem>)
val recycleBinPath = filesDir.absolutePath
val mediaToDelete = ArrayList<Medium>()
media.filter { !getDoesFilePathExist(it.path) }.forEach {
if (it.path.startsWith(recycleBinPath)) {
mediumDao.deleteMediumPath(it.path.removePrefix(recycleBinPath))
} else {
mediumDao.deleteMediumPath(it.path)
mediaToDelete.add(it)
}
}
mediumDao.deleteMedia(*mediaToDelete.toTypedArray())
}.start()
}

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.interfaces
import android.arch.persistence.room.Dao
import android.arch.persistence.room.Delete
import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy.REPLACE
import android.arch.persistence.room.Query
@ -26,6 +27,9 @@ interface MediumDao {
@Insert(onConflict = REPLACE)
fun insertAll(media: List<Medium>)
@Delete
fun deleteMedia(vararg medium: Medium)
@Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE")
fun deleteMediumPath(path: String)