mirror of
https://github.com/gotson/komga.git
synced 2025-12-16 13:33:49 +01:00
perf: convert to cbz on first scan
This commit is contained in:
parent
33cd19ae04
commit
b724f205cd
5 changed files with 29 additions and 10 deletions
|
|
@ -20,6 +20,11 @@ sealed class Task(priority: Int = DEFAULT_PRIORITY, val groupId: String? = null)
|
|||
override fun toString(): String = "ScanLibrary(libraryId='$libraryId', priority='$priority')"
|
||||
}
|
||||
|
||||
class FindBooksToConvert(val libraryId: String, priority: Int = DEFAULT_PRIORITY) : Task(priority) {
|
||||
override fun uniqueId() = "FIND_BOOKS_TO_CONVERT_$libraryId"
|
||||
override fun toString(): String = "FindBooksToConvert(libraryId='$libraryId', priority='$priority')"
|
||||
}
|
||||
|
||||
class EmptyTrash(val libraryId: String, priority: Int = DEFAULT_PRIORITY) : Task(priority) {
|
||||
override fun uniqueId() = "EMPTY_TRASH_$libraryId"
|
||||
override fun toString(): String = "EmptyTrash(libraryId='$libraryId', priority='$priority')"
|
||||
|
|
|
|||
|
|
@ -60,10 +60,17 @@ class TaskHandler(
|
|||
taskReceiver.hashBooksWithoutHash(library)
|
||||
taskReceiver.hashBookPagesWithMissingHash(library)
|
||||
taskReceiver.repairExtensions(library, LOWEST_PRIORITY)
|
||||
taskReceiver.convertBooksToCbz(library, LOWEST_PRIORITY)
|
||||
taskReceiver.findBooksToConvert(library, LOWEST_PRIORITY)
|
||||
taskReceiver.removeDuplicatePages(library, LOWEST_PRIORITY)
|
||||
} ?: logger.warn { "Cannot execute task $task: Library does not exist" }
|
||||
|
||||
is Task.FindBooksToConvert ->
|
||||
libraryRepository.findByIdOrNull(task.libraryId)?.let { library ->
|
||||
bookConverter.getConvertibleBooks(library).forEach {
|
||||
taskReceiver.convertBookToCbz(it, task.priority + 1)
|
||||
}
|
||||
} ?: logger.warn { "Cannot execute task $task: Library does not exist" }
|
||||
|
||||
is Task.EmptyTrash ->
|
||||
libraryRepository.findByIdOrNull(task.libraryId)?.let { library ->
|
||||
libraryContentLifecycle.emptyTrash(library)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class TaskReceiver(
|
|||
libraryIds = listOf(library.id),
|
||||
mediaStatus = listOf(Media.Status.UNKNOWN, Media.Status.OUTDATED),
|
||||
),
|
||||
UnpagedSorted(Sort.by(Sort.Order.asc("seriesId"), Sort.Order.asc("number")))
|
||||
UnpagedSorted(Sort.by(Sort.Order.asc("seriesId"), Sort.Order.asc("number"))),
|
||||
).forEach {
|
||||
submitTask(Task.AnalyzeBook(it.id, groupId = it.seriesId))
|
||||
}
|
||||
|
|
@ -78,11 +78,12 @@ class TaskReceiver(
|
|||
}
|
||||
}
|
||||
|
||||
fun convertBooksToCbz(library: Library, priority: Int = DEFAULT_PRIORITY) {
|
||||
if (library.convertToCbz)
|
||||
bookConverter.getConvertibleBooks(library).forEach {
|
||||
submitTask(Task.ConvertBook(it.id, priority, it.seriesId))
|
||||
}
|
||||
fun findBooksToConvert(library: Library, priority: Int = DEFAULT_PRIORITY) {
|
||||
submitTask(Task.FindBooksToConvert(library.id, priority))
|
||||
}
|
||||
|
||||
fun convertBookToCbz(book: Book, priority: Int = DEFAULT_PRIORITY) {
|
||||
submitTask(Task.ConvertBook(book.id, priority, book.seriesId))
|
||||
}
|
||||
|
||||
fun repairExtensions(library: Library, priority: Int = DEFAULT_PRIORITY) {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,13 @@ class BookConverter(
|
|||
private val skippedRepairs = mutableListOf<String>()
|
||||
|
||||
fun getConvertibleBooks(library: Library): Collection<Book> =
|
||||
bookRepository.findAllByLibraryIdAndMediaTypes(library.id, convertibleTypes)
|
||||
if (library.convertToCbz)
|
||||
bookRepository.findAllByLibraryIdAndMediaTypes(library.id, convertibleTypes)
|
||||
.also { logger.info { "Found ${it.size} books to convert" } }
|
||||
else {
|
||||
logger.info { "CBZ conversion is not enabled, skipping" }
|
||||
emptyList()
|
||||
}
|
||||
|
||||
fun convertToCbz(book: Book) {
|
||||
// perform various checks
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ komga:
|
|||
file: ":memory:"
|
||||
cors.allowed-origins:
|
||||
- http://localhost:8081
|
||||
task-consumers: 5
|
||||
task-consumers-max: 20
|
||||
# task-consumers: 5
|
||||
# task-consumers-max: 20
|
||||
# delete-empty-collections: true
|
||||
# delete-empty-read-lists: true
|
||||
oauth2-account-creation: false
|
||||
|
|
|
|||
Loading…
Reference in a new issue