Skip to content

Commit

Permalink
Feature/update to exposed v0.57.0 (#1150)
Browse files Browse the repository at this point in the history
* Update to exposed-migrations v3.5.0

* Update to kotlin-logging v7.0.0

* Update to exposed v0.46.0

* Update to exposed v0.47.0

* Update to exposed v0.55.0

* Update to exposed v0.56.0

* Update to exposed v0.57.0
  • Loading branch information
schroda authored Dec 8, 2024
1 parent f926714 commit 1d541a3
Show file tree
Hide file tree
Showing 87 changed files with 459 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import com.typesafe.config.ConfigValue
import com.typesafe.config.ConfigValueFactory
import com.typesafe.config.parser.ConfigDocument
import com.typesafe.config.parser.ConfigDocumentFactory
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import mu.KotlinLogging
import java.io.File

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import ch.qos.logback.core.rolling.RollingFileAppender
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy
import ch.qos.logback.core.util.FileSize
import com.typesafe.config.Config
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.DelegatingKLogger
import io.github.oshai.kotlinlogging.KotlinLogging
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -73,7 +74,7 @@ private fun createRollingFileAppender(
}

private fun getBaseLogger(): ch.qos.logback.classic.Logger =
(KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger)
((KotlinLogging.logger(Logger.ROOT_LOGGER_NAME) as DelegatingKLogger<*>).underlyingLogger as ch.qos.logback.classic.Logger)

private fun getLogger(name: String): ch.qos.logback.classic.Logger {
val context = LoggerFactory.getILoggerFactory() as LoggerContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import com.russhwolf.settings.Settings
import com.russhwolf.settings.serialization.decodeValue
import com.russhwolf.settings.serialization.decodeValueOrNull
import com.russhwolf.settings.serialization.encodeValue
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerializationException
import kotlinx.serialization.builtins.SetSerializer
import kotlinx.serialization.builtins.serializer
import mu.KotlinLogging
import xyz.nulldev.androidcompat.util.SafePath
import xyz.nulldev.ts.config.ApplicationRootDir
import java.util.Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package xyz.nulldev.androidcompat.service
import android.app.Service
import android.content.Context
import android.content.Intent
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.ConcurrentHashMap
import kotlin.concurrent.thread

Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ serialization = "1.7.3"
okhttp = "5.0.0-alpha.14" # Major version is locked by Tachiyomi extensions
javalin = "6.3.0"
jackson = "2.18.2" # jackson version locked by javalin, ref: `io.javalin.core.util.OptionalDependency`
exposed = "0.40.1"
exposed = "0.57.0"
dex2jar = "v64" # Stuck until https://github.com/ThexXTURBOXx/dex2jar/issues/27 is fixed
polyglot = "24.1.1"
settings = "1.3.0"
Expand Down Expand Up @@ -36,7 +36,7 @@ serialization-xml = { module = "io.github.pdvrieze.xmlutil:serialization-jvm", v
# Logging
slf4japi = "org.slf4j:slf4j-api:2.0.16"
logback = "ch.qos.logback:logback-classic:1.5.12"
kotlinlogging = "io.github.microutils:kotlin-logging:3.0.5"
kotlinlogging = "io.github.oshai:kotlin-logging-jvm:7.0.0"

# OkHttp
okhttp-core = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
Expand Down Expand Up @@ -66,7 +66,7 @@ exposed-javatime = { module = "org.jetbrains.exposed:exposed-java-time", version
h2 = "com.h2database:h2:1.4.200" # current database driver, can't update to h2 v2 without sql migration

# Exposed Migrations
exposed-migrations = "com.github.Suwayomi:exposed-migrations:3.2.0"
exposed-migrations = "com.github.Suwayomi:exposed-migrations:3.5.0"

# Dependency Injection
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor
import eu.kanade.tachiyomi.network.interceptor.IgnoreGzipInterceptor
import eu.kanade.tachiyomi.network.interceptor.UncaughtExceptionInterceptor
import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import mu.KotlinLogging
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.brotli.BrotliInterceptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.network.awaitSuccess
import eu.kanade.tachiyomi.network.parseAs
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
Expand All @@ -15,7 +16,6 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import okhttp3.Cookie
import okhttp3.HttpUrl
import okhttp3.Interceptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
import eu.kanade.tachiyomi.util.storage.EpubFile
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import mu.KotlinLogging
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
import nl.adaptivity.xmlutil.core.KtXmlReader
import nl.adaptivity.xmlutil.serialization.XML
import org.apache.commons.compress.archivers.zip.ZipFile
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.insertAndGetId
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.registerCatalogueSource
import suwayomi.tachidesk.manga.impl.util.storage.ImageUtil
Expand Down Expand Up @@ -444,7 +444,7 @@ class LocalSource(

fun register() {
transaction {
val sourceRecord = SourceTable.select { SourceTable.id eq ID }.firstOrNull()
val sourceRecord = SourceTable.selectAll().where { SourceTable.id eq ID }.firstOrNull()

if (sourceRecord == null) {
// must do this to avoid database integrity errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package suwayomi.tachidesk.global.impl

import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
Expand All @@ -22,7 +21,7 @@ object GlobalMeta {
transaction {
val meta =
transaction {
GlobalMetaTable.select { GlobalMetaTable.key eq key }
GlobalMetaTable.selectAll().where { GlobalMetaTable.key eq key }
}.firstOrNull()

if (meta == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package suwayomi.tachidesk.graphql

import com.expediagroup.graphql.server.extensions.toGraphQLError
import graphql.execution.DataFetcherResult
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging

val logger = KotlinLogging.logger { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.dataloader.DataLoader
import org.dataloader.DataLoaderFactory
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.CategoryNodeList
import suwayomi.tachidesk.graphql.types.CategoryNodeList.Companion.toNodeList
Expand All @@ -32,7 +32,8 @@ class CategoryDataLoader : KotlinDataLoader<Int, CategoryType> {
addLogger(Slf4jSqlDebugLogger)
val categories =
CategoryTable
.select { CategoryTable.id inList ids }
.selectAll()
.where { CategoryTable.id inList ids }
.map { CategoryType(it) }
.associateBy { it.id }
ids.map { categories[it] }
Expand All @@ -50,7 +51,7 @@ class CategoryForIdsDataLoader : KotlinDataLoader<List<Int>, CategoryNodeList> {
transaction {
addLogger(Slf4jSqlDebugLogger)
val ids = categoryIds.flatten().distinct()
val categories = CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
val categories = CategoryTable.selectAll().where { CategoryTable.id inList ids }.map { CategoryType(it) }
categoryIds.map { categoryIds ->
categories.filter { it.id in categoryIds }.toNodeList()
}
Expand All @@ -70,7 +71,8 @@ class CategoriesForMangaDataLoader : KotlinDataLoader<Int, CategoryNodeList> {
val itemsByRef =
CategoryMangaTable
.innerJoin(CategoryTable)
.select { CategoryMangaTable.manga inList ids }
.selectAll()
.where { CategoryMangaTable.manga inList ids }
.map { Pair(it[CategoryMangaTable.manga].value, CategoryType(it)) }
.groupBy { it.first }
.mapValues { it.value.map { pair -> pair.second } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.jetbrains.exposed.sql.SortOrder
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.count
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.ChapterNodeList
import suwayomi.tachidesk.graphql.types.ChapterNodeList.Companion.toNodeList
Expand All @@ -34,7 +34,8 @@ class ChapterDataLoader : KotlinDataLoader<Int, ChapterType?> {
addLogger(Slf4jSqlDebugLogger)
val chapters =
ChapterTable
.select { ChapterTable.id inList ids }
.selectAll()
.where { ChapterTable.id inList ids }
.map { ChapterType(it) }
.associateBy { it.id }
ids.map { chapters[it] }
Expand All @@ -53,7 +54,8 @@ class ChaptersForMangaDataLoader : KotlinDataLoader<Int, ChapterNodeList> {
addLogger(Slf4jSqlDebugLogger)
val chaptersByMangaId =
ChapterTable
.select { ChapterTable.manga inList ids }
.selectAll()
.where { ChapterTable.manga inList ids }
.map { ChapterType(it) }
.groupBy { it.mangaId }
ids.map { (chaptersByMangaId[it] ?: emptyList()).toNodeList() }
Expand All @@ -72,9 +74,11 @@ class DownloadedChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
addLogger(Slf4jSqlDebugLogger)
val downloadedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isDownloaded.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isDownloaded eq true) }
.groupBy(ChapterTable.manga)
.select(ChapterTable.manga, ChapterTable.isDownloaded.count())
.where {
(ChapterTable.manga inList ids) and
(ChapterTable.isDownloaded eq true)
}.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isDownloaded.count()] }
ids.map { downloadedChapterCountByMangaId[it]?.toInt() ?: 0 }
}
Expand All @@ -92,9 +96,11 @@ class UnreadChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
addLogger(Slf4jSqlDebugLogger)
val unreadChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isRead.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.groupBy(ChapterTable.manga)
.select(ChapterTable.manga, ChapterTable.isRead.count())
.where {
(ChapterTable.manga inList ids) and
(ChapterTable.isRead eq false)
}.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isRead.count()] }
ids.map { unreadChapterCountByMangaId[it]?.toInt() ?: 0 }
}
Expand All @@ -112,9 +118,11 @@ class BookmarkedChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
addLogger(Slf4jSqlDebugLogger)
val bookmarkedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isBookmarked.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isBookmarked eq true) }
.groupBy(ChapterTable.manga)
.select(ChapterTable.manga, ChapterTable.isBookmarked.count())
.where {
(ChapterTable.manga inList ids) and
(ChapterTable.isBookmarked eq true)
}.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isBookmarked.count()] }
ids.map { bookmarkedChapterCountByMangaId[it]?.toInt() ?: 0 }
}
Expand All @@ -132,9 +140,14 @@ class HasDuplicateChaptersForMangaDataLoader : KotlinDataLoader<Int, Boolean> {
addLogger(Slf4jSqlDebugLogger)
val duplicatedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.chapter_number, ChapterTable.chapter_number.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.chapter_number greaterEq 0f) }
.groupBy(ChapterTable.manga, ChapterTable.chapter_number)
.select(ChapterTable.manga, ChapterTable.chapter_number, ChapterTable.chapter_number.count())
.where {
(
ChapterTable.manga inList
ids
) and
(ChapterTable.chapter_number greaterEq 0f)
}.groupBy(ChapterTable.manga, ChapterTable.chapter_number)
.having { ChapterTable.chapter_number.count() greater 1 }
.associate { it[ChapterTable.manga].value to it[ChapterTable.chapter_number.count()] }

Expand All @@ -154,7 +167,8 @@ class LastReadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?> {
addLogger(Slf4jSqlDebugLogger)
val lastReadChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) }
.selectAll()
.where { (ChapterTable.manga inList ids) }
.orderBy(ChapterTable.lastReadAt to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> lastReadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
Expand All @@ -173,7 +187,8 @@ class LatestReadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?>
addLogger(Slf4jSqlDebugLogger)
val latestReadChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq true) }
.selectAll()
.where { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq true) }
.orderBy(ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> latestReadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
Expand All @@ -192,7 +207,8 @@ class LatestFetchedChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType
addLogger(Slf4jSqlDebugLogger)
val latestFetchedChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) }
.selectAll()
.where { (ChapterTable.manga inList ids) }
.orderBy(ChapterTable.fetchedAt to SortOrder.DESC, ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> latestFetchedChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
Expand All @@ -211,7 +227,8 @@ class LatestUploadedChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterTyp
addLogger(Slf4jSqlDebugLogger)
val latestUploadedChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) }
.selectAll()
.where { (ChapterTable.manga inList ids) }
.orderBy(ChapterTable.date_upload to SortOrder.DESC, ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> latestUploadedChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
Expand All @@ -230,7 +247,8 @@ class FirstUnreadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?>
addLogger(Slf4jSqlDebugLogger)
val firstUnreadChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.selectAll()
.where { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.orderBy(ChapterTable.sourceOrder to SortOrder.ASC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> firstUnreadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
Expand Down
Loading

0 comments on commit 1d541a3

Please sign in to comment.