Replace CategoryUpdate with dedicated update queries (#3693)

Assisted-by: Claude:claude-opus-5
This commit is contained in:
AntsyLich
2026-08-05 00:40:08 +06:00
committed by GitHub
parent 3d20bcc6b6
commit 21c6357967
10 changed files with 35 additions and 87 deletions
@@ -3,7 +3,6 @@ package tachiyomi.domain.category.interactor
import logcat.LogPriority
import tachiyomi.core.common.util.lang.withNonCancellableContext
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.category.repository.CategoryRepository
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.library.service.LibraryPreferences
@@ -22,13 +21,7 @@ class DeleteCategory(
return@withNonCancellableContext Result.InternalError(e)
}
val categories = categoryRepository.getAll()
val updates = categories.mapIndexed { index, category ->
CategoryUpdate(
id = category.id,
order = index.toLong(),
)
}
val orderedIds = categoryRepository.getAll().map { it.id }
val defaultCategory = libraryPreferences.defaultCategory.get()
if (defaultCategory == categoryId.toInt()) {
@@ -50,7 +43,7 @@ class DeleteCategory(
}
try {
categoryRepository.updatePartial(updates)
categoryRepository.updateAllOrders(orderedIds = orderedIds)
Result.Success
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
@@ -4,7 +4,6 @@ import logcat.LogPriority
import tachiyomi.core.common.util.lang.withNonCancellableContext
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.category.repository.CategoryRepository
class RenameCategory(
@@ -12,13 +11,8 @@ class RenameCategory(
) {
suspend fun await(categoryId: Long, name: String) = withNonCancellableContext {
val update = CategoryUpdate(
id = categoryId,
name = name,
)
try {
categoryRepository.updatePartial(update)
categoryRepository.updateName(categoryId = categoryId, name = name)
Result.Success
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
@@ -6,7 +6,6 @@ import logcat.LogPriority
import tachiyomi.core.common.util.lang.withNonCancellableContext
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.category.repository.CategoryRepository
class ReorderCategory(
@@ -28,14 +27,7 @@ class ReorderCategory(
try {
categories.add(newIndex, categories.removeAt(currentIndex))
val updates = categories.mapIndexed { index, category ->
CategoryUpdate(
id = category.id,
order = index.toLong(),
)
}
categoryRepository.updatePartial(updates)
categoryRepository.updateAllOrders(orderedIds = categories.map { it.id })
Result.Success
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
@@ -1,7 +1,6 @@
package tachiyomi.domain.category.interactor
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.category.repository.CategoryRepository
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.plus
@@ -20,12 +19,7 @@ class SetSortModeForCategory(
preferences.randomSortSeed.set(Random.nextInt())
}
if (category != null && preferences.categorizedDisplaySettings.get()) {
categoryRepository.updatePartial(
CategoryUpdate(
id = category.id,
flags = flags,
),
)
categoryRepository.updateFlags(categoryId = category.id, flags = flags)
} else {
preferences.sortingMode.set(LibrarySort(type, direction))
categoryRepository.updateAllFlags(flags)
@@ -1,24 +0,0 @@
package tachiyomi.domain.category.interactor
import tachiyomi.core.common.util.lang.withNonCancellableContext
import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.category.repository.CategoryRepository
class UpdateCategory(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(payload: CategoryUpdate): Result = withNonCancellableContext {
try {
categoryRepository.updatePartial(payload)
Result.Success
} catch (e: Exception) {
Result.Error(e)
}
}
sealed interface Result {
data object Success : Result
data class Error(val error: Exception) : Result
}
}
@@ -1,8 +0,0 @@
package tachiyomi.domain.category.model
data class CategoryUpdate(
val id: Long,
val name: String? = null,
val order: Long? = null,
val flags: Long? = null,
)
@@ -2,7 +2,6 @@ package tachiyomi.domain.category.repository
import kotlinx.coroutines.flow.Flow
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.category.model.CategoryUpdate
interface CategoryRepository {
@@ -18,11 +17,13 @@ interface CategoryRepository {
suspend fun insert(category: Category)
suspend fun updatePartial(update: CategoryUpdate)
suspend fun updateName(categoryId: Long, name: String)
suspend fun updatePartial(updates: List<CategoryUpdate>)
suspend fun updateFlags(categoryId: Long, flags: Long)
suspend fun updateAllFlags(flags: Long?)
suspend fun updateAllOrders(orderedIds: List<Long>)
suspend fun delete(categoryId: Long)
}