Save categories when manga is unfavorited (#335)

Fixes non-library manga with categories in backups
This commit is contained in:
Mitchell Syer
2022-04-07 21:40:39 -04:00
committed by GitHub
parent a26b8ecca0
commit db5c5ed534
2 changed files with 9 additions and 9 deletions

View File

@@ -90,7 +90,7 @@ object CategoryManga {
return transaction { return transaction {
CategoryMangaTable.innerJoin(MangaTable) CategoryMangaTable.innerJoin(MangaTable)
.slice(selectedColumns) .slice(selectedColumns)
.select { CategoryMangaTable.category eq categoryId } .select { (MangaTable.inLibrary eq true) and (CategoryMangaTable.category eq categoryId) }
.map(transform) .map(transform)
} }
} }

View File

@@ -7,7 +7,6 @@ package suwayomi.tachidesk.manga.impl
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
@@ -24,13 +23,15 @@ object Library {
if (!manga.inLibrary) { if (!manga.inLibrary) {
transaction { transaction {
val defaultCategories = CategoryTable.select { CategoryTable.isDefault eq true }.toList() val defaultCategories = CategoryTable.select { CategoryTable.isDefault eq true }.toList()
val existingCategories = CategoryMangaTable.select { CategoryMangaTable.manga eq mangaId }.toList()
MangaTable.update({ MangaTable.id eq manga.id }) { MangaTable.update({ MangaTable.id eq manga.id }) {
it[inLibrary] = true it[inLibrary] = true
it[inLibraryAt] = Instant.now().epochSecond it[inLibraryAt] = Instant.now().epochSecond
it[defaultCategory] = defaultCategories.isEmpty() it[defaultCategory] = defaultCategories.isEmpty() && existingCategories.isEmpty()
} }
if (existingCategories.isEmpty()) {
defaultCategories.forEach { category -> defaultCategories.forEach { category ->
CategoryMangaTable.insert { CategoryMangaTable.insert {
it[CategoryMangaTable.category] = category[CategoryTable.id].value it[CategoryMangaTable.category] = category[CategoryTable.id].value
@@ -40,6 +41,7 @@ object Library {
} }
} }
} }
}
suspend fun removeMangaFromLibrary(mangaId: Int) { suspend fun removeMangaFromLibrary(mangaId: Int) {
val manga = getManga(mangaId) val manga = getManga(mangaId)
@@ -47,9 +49,7 @@ object Library {
transaction { transaction {
MangaTable.update({ MangaTable.id eq manga.id }) { MangaTable.update({ MangaTable.id eq manga.id }) {
it[inLibrary] = false it[inLibrary] = false
it[defaultCategory] = true }
}
CategoryMangaTable.deleteWhere { CategoryMangaTable.manga eq mangaId }
} }
} }
} }