mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Check category order before restoring from backup
Closes #632 Co-authored-by: Cologler <10906962+Cologler@users.noreply.github.com>
This commit is contained in:
parent
87fe64468c
commit
119bcbf8ed
1 changed files with 12 additions and 6 deletions
|
@ -17,14 +17,20 @@ class CategoriesRestorer(
|
||||||
if (backupCategories.isNotEmpty()) {
|
if (backupCategories.isNotEmpty()) {
|
||||||
val dbCategories = getCategories.await()
|
val dbCategories = getCategories.await()
|
||||||
val dbCategoriesByName = dbCategories.associateBy { it.name }
|
val dbCategoriesByName = dbCategories.associateBy { it.name }
|
||||||
|
var nextOrder = dbCategories.maxOfOrNull { it.order }?.plus(1) ?: 0
|
||||||
|
|
||||||
val categories = backupCategories.map {
|
val categories = backupCategories
|
||||||
dbCategoriesByName[it.name]
|
.sortedBy { it.order }
|
||||||
?: handler.awaitOneExecutable {
|
.map {
|
||||||
categoriesQueries.insert(it.name, it.order, it.flags)
|
val dbCategory = dbCategoriesByName[it.name]
|
||||||
|
if (dbCategory != null) return@map dbCategory
|
||||||
|
val order = nextOrder++
|
||||||
|
handler.awaitOneExecutable {
|
||||||
|
categoriesQueries.insert(it.name, order, it.flags)
|
||||||
categoriesQueries.selectLastInsertedRowId()
|
categoriesQueries.selectLastInsertedRowId()
|
||||||
}.let { id -> it.toCategory(id) }
|
}
|
||||||
}
|
.let { id -> it.toCategory(id).copy(order = order) }
|
||||||
|
}
|
||||||
|
|
||||||
libraryPreferences.categorizedDisplaySettings().set(
|
libraryPreferences.categorizedDisplaySettings().set(
|
||||||
(dbCategories + categories)
|
(dbCategories + categories)
|
||||||
|
|
Loading…
Reference in a new issue