make sure to always create a new thread for inserting some things in db

This commit is contained in:
tibbi 2020-04-25 16:20:21 +02:00
parent 963fd57113
commit 462182271d
2 changed files with 13 additions and 6 deletions

View file

@ -955,7 +955,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
// update directories and media files in the local db, delete invalid items // update directories and media files in the local db, delete invalid items
updateDBDirectory(directory) updateDBDirectory(directory)
if (!directory.isRecycleBin()) { if (!directory.isRecycleBin()) {
mediaDB.insertAll(curMedia) Thread {
mediaDB.insertAll(curMedia)
}.start()
} }
getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { getCachedMedia(directory.path, getVideosOnly, getImagesOnly) {
@ -1029,10 +1031,13 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
dirs.add(newDir) dirs.add(newDir)
setupAdapter(dirs) setupAdapter(dirs)
try { try {
directoryDao.insert(newDir) // make sure to create a new thread for these operations, dont just use the common bg thread
if (folder != RECYCLE_BIN) { Thread {
mediaDB.insertAll(newMedia) directoryDao.insert(newDir)
} if (folder != RECYCLE_BIN) {
mediaDB.insertAll(newMedia)
}
}.start()
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
} }

View file

@ -873,7 +873,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
if (!isFromCache) { if (!isFromCache) {
val mediaToInsert = (mMedia).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium } val mediaToInsert = (mMedia).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium }
try { try {
mediaDB.insertAll(mediaToInsert) Thread {
mediaDB.insertAll(mediaToInsert)
}.start()
} catch (e: Exception) { } catch (e: Exception) {
} }
} }