Skip to content

Commit

Permalink
perf: convert to cbz on first scan
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Feb 17, 2022
1 parent 33cd19a commit b724f20
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions komga/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b724f20

Please sign in to comment.