diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/LocalSource.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/LocalSource.kt index 21e420a1..ebdba662 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/LocalSource.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/LocalSource.kt @@ -34,6 +34,7 @@ import org.kodein.di.DI import org.kodein.di.conf.global import org.kodein.di.instance import rx.Observable +import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.registerCatalogueSource import suwayomi.tachidesk.manga.impl.util.storage.ImageUtil import suwayomi.tachidesk.manga.model.table.ExtensionTable import suwayomi.tachidesk.manga.model.table.SourceTable @@ -89,7 +90,7 @@ class LocalSource : CatalogueSource { } } - fun addDbRecords() { + fun register() { transaction { val sourceRecord = SourceTable.select { SourceTable.id eq ID }.firstOrNull() @@ -115,6 +116,8 @@ class LocalSource : CatalogueSource { } } } + + registerCatalogueSource(ID to LocalSource()) } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt index 9d015daf..c303b64d 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt @@ -10,7 +10,6 @@ package suwayomi.tachidesk.manga.impl.util.source import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceFactory -import eu.kanade.tachiyomi.source.local.LocalSource import eu.kanade.tachiyomi.source.online.HttpSource import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction @@ -24,9 +23,7 @@ import suwayomi.tachidesk.server.ApplicationDirs import java.util.concurrent.ConcurrentHashMap object GetCatalogueSource { - private val sourceCache = ConcurrentHashMap( - mapOf(LocalSource.ID to LocalSource()) - ) + private val sourceCache = ConcurrentHashMap() private val applicationDirs by DI.global.instance() fun getCatalogueSource(sourceId: Long): CatalogueSource? { @@ -63,6 +60,10 @@ object GetCatalogueSource { return getCatalogueSource(sourceId) ?: StubSource(sourceId) } + fun registerCatalogueSource(sourcePair: Pair) { + sourceCache += sourcePair + } + fun invalidateSourceCache(sourceId: Long) { sourceCache.remove(sourceId) } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index 64fc866b..c529e549 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -119,7 +119,7 @@ fun applicationSetup() { databaseUp() - LocalSource.addDbRecords() + LocalSource.register() // create system tray if (serverConfig.systemTrayEnabled) { diff --git a/server/src/test/kotlin/suwayomi/tachidesk/ApplicationTest.kt b/server/src/test/kotlin/suwayomi/tachidesk/ApplicationTest.kt index fe543408..a663a220 100644 --- a/server/src/test/kotlin/suwayomi/tachidesk/ApplicationTest.kt +++ b/server/src/test/kotlin/suwayomi/tachidesk/ApplicationTest.kt @@ -151,7 +151,7 @@ open class ApplicationTest { databaseUp(db) - LocalSource.addDbRecords() + LocalSource.register() } } } diff --git a/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/SourceControllerTest.kt b/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/SourceControllerTest.kt deleted file mode 100644 index a84fad6d..00000000 --- a/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/SourceControllerTest.kt +++ /dev/null @@ -1,46 +0,0 @@ -package suwayomi.tachidesk.manga.controller - -/* - * Copyright (C) Contributors to the Suwayomi project - * - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -import org.jetbrains.exposed.sql.deleteAll -import org.jetbrains.exposed.sql.transactions.transaction -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestInstance -import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS -import suwayomi.tachidesk.manga.impl.Category -import suwayomi.tachidesk.manga.model.table.CategoryTable -import suwayomi.tachidesk.ApplicationTest - -@TestInstance(PER_CLASS) -internal class SourceControllerTest : ApplicationTest() { - @Test - fun categoryReorder() { - Category.createCategory("foo") - Category.createCategory("bar") - val cats = Category.getCategoryList() - val foo = cats.asSequence().filter { it.name == "foo" }.first() - val bar = cats.asSequence().filter { it.name == "bar" }.first() - assertEquals(1, foo.order) - assertEquals(2, bar.order) - Category.reorderCategory(1, 2) - val catsReordered = Category.getCategoryList() - val fooReordered = catsReordered.asSequence().filter { it.name == "foo" }.first() - val barReordered = catsReordered.asSequence().filter { it.name == "bar" }.first() - assertEquals(2, fooReordered.order) - assertEquals(1, barReordered.order) - } - - @AfterEach - internal fun tearDown() { - transaction { - CategoryTable.deleteAll() - } - } -}