mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-20 11:13:33 -05:00
Add logic to only update specific categories (#520)
Makes it possible to only update specific categories. In case a manga is in an excluded category it will be excluded even if it is also in an included category.
This commit is contained in:
@@ -19,6 +19,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga.removeMangaFromCategory
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.IncludeInUpdate
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryTable
|
||||
@@ -49,11 +50,12 @@ object Category {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCategory(categoryId: Int, name: String?, isDefault: Boolean?) {
|
||||
fun updateCategory(categoryId: Int, name: String?, isDefault: Boolean?, includeInUpdate: Int?) {
|
||||
transaction {
|
||||
CategoryTable.update({ CategoryTable.id eq categoryId }) {
|
||||
if (name != null && !name.equals(DEFAULT_CATEGORY_NAME, ignoreCase = true)) it[CategoryTable.name] = name
|
||||
if (isDefault != null) it[CategoryTable.isDefault] = isDefault
|
||||
if (includeInUpdate != null) it[CategoryTable.includeInUpdate] = includeInUpdate
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +102,7 @@ object Category {
|
||||
private fun addDefaultIfNecessary(categories: List<CategoryDataClass>): List<CategoryDataClass> {
|
||||
val defaultCategorySize = MangaTable.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }.count().toInt()
|
||||
return if (defaultCategorySize > 0) {
|
||||
listOf(CategoryDataClass(DEFAULT_CATEGORY_ID, 0, DEFAULT_CATEGORY_NAME, true, defaultCategorySize)) + categories
|
||||
listOf(CategoryDataClass(DEFAULT_CATEGORY_ID, 0, DEFAULT_CATEGORY_NAME, true, defaultCategorySize, IncludeInUpdate.UNSET)) + categories
|
||||
} else {
|
||||
categories
|
||||
}
|
||||
|
||||
@@ -116,4 +116,20 @@ object CategoryManga {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getMangasCategories(mangaIDs: List<Int>): Map<Int, List<CategoryDataClass>> {
|
||||
return buildMap {
|
||||
transaction {
|
||||
CategoryMangaTable.innerJoin(CategoryTable)
|
||||
.select { CategoryMangaTable.manga inList mangaIDs }
|
||||
.groupBy { it[CategoryMangaTable.manga] }
|
||||
.forEach {
|
||||
val mangaId = it.key.value
|
||||
val categories = it.value
|
||||
|
||||
set(mangaId, categories.map { category -> CategoryTable.toDataClass(category) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class Updater : IUpdater {
|
||||
|
||||
override fun addMangasToQueue(mangas: List<MangaDataClass>) {
|
||||
mangas.forEach { tracker[it.id] = UpdateJob(it) }
|
||||
_status.update { UpdateStatus(tracker.values.toList(), true) }
|
||||
_status.update { UpdateStatus(tracker.values.toList(), mangas.isNotEmpty()) }
|
||||
mangas.forEach { addMangaToQueue(it) }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user