add batch deleting of invalid files from room DB
This commit is contained in:
parent
ba732bd15a
commit
730ca8b5c0
2 changed files with 8 additions and 1 deletions
|
@ -391,13 +391,16 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
|
||||||
callback(grouped.clone() as ArrayList<ThumbnailItem>)
|
callback(grouped.clone() as ArrayList<ThumbnailItem>)
|
||||||
|
|
||||||
val recycleBinPath = filesDir.absolutePath
|
val recycleBinPath = filesDir.absolutePath
|
||||||
|
val mediaToDelete = ArrayList<Medium>()
|
||||||
media.filter { !getDoesFilePathExist(it.path) }.forEach {
|
media.filter { !getDoesFilePathExist(it.path) }.forEach {
|
||||||
if (it.path.startsWith(recycleBinPath)) {
|
if (it.path.startsWith(recycleBinPath)) {
|
||||||
mediumDao.deleteMediumPath(it.path.removePrefix(recycleBinPath))
|
mediumDao.deleteMediumPath(it.path.removePrefix(recycleBinPath))
|
||||||
} else {
|
} else {
|
||||||
mediumDao.deleteMediumPath(it.path)
|
mediaToDelete.add(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mediumDao.deleteMedia(*mediaToDelete.toTypedArray())
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.simplemobiletools.gallery.interfaces
|
package com.simplemobiletools.gallery.interfaces
|
||||||
|
|
||||||
import android.arch.persistence.room.Dao
|
import android.arch.persistence.room.Dao
|
||||||
|
import android.arch.persistence.room.Delete
|
||||||
import android.arch.persistence.room.Insert
|
import android.arch.persistence.room.Insert
|
||||||
import android.arch.persistence.room.OnConflictStrategy.REPLACE
|
import android.arch.persistence.room.OnConflictStrategy.REPLACE
|
||||||
import android.arch.persistence.room.Query
|
import android.arch.persistence.room.Query
|
||||||
|
@ -26,6 +27,9 @@ interface MediumDao {
|
||||||
@Insert(onConflict = REPLACE)
|
@Insert(onConflict = REPLACE)
|
||||||
fun insertAll(media: List<Medium>)
|
fun insertAll(media: List<Medium>)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun deleteMedia(vararg medium: Medium)
|
||||||
|
|
||||||
@Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE")
|
@Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE")
|
||||||
fun deleteMediumPath(path: String)
|
fun deleteMediumPath(path: String)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue