mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-22 05:05:38 +03: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,13 +17,19 @@ 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(
|
||||||
|
|
Loading…
Reference in a new issue