fix meta update changing all keys (#314)

This commit is contained in:
Aria Moradi
2022-03-18 00:14:22 +03:30
committed by GitHub
parent 186ace4343
commit fa035ad9be
2 changed files with 13 additions and 7 deletions

View File

@@ -201,8 +201,10 @@ object Chapter {
val chapterId = val chapterId =
ChapterTable.select { (ChapterTable.manga eq mangaId) and (ChapterTable.sourceOrder eq chapterIndex) } ChapterTable.select { (ChapterTable.manga eq mangaId) and (ChapterTable.sourceOrder eq chapterIndex) }
.first()[ChapterTable.id].value .first()[ChapterTable.id].value
val meta = val meta = transaction {
transaction { ChapterMetaTable.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) } }.firstOrNull() ChapterMetaTable.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
}.firstOrNull()
if (meta == null) { if (meta == null) {
ChapterMetaTable.insert { ChapterMetaTable.insert {
it[ChapterMetaTable.key] = key it[ChapterMetaTable.key] = key
@@ -210,7 +212,7 @@ object Chapter {
it[ChapterMetaTable.ref] = chapterId it[ChapterMetaTable.ref] = chapterId
} }
} else { } else {
ChapterMetaTable.update { ChapterMetaTable.update({ (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }) {
it[ChapterMetaTable.value] = value it[ChapterMetaTable.value] = value
} }
} }

View File

@@ -146,8 +146,10 @@ object Manga {
transaction { transaction {
val manga = MangaTable.select { MangaTable.id eq mangaId } val manga = MangaTable.select { MangaTable.id eq mangaId }
.first()[MangaTable.id] .first()[MangaTable.id]
val meta = val meta = transaction {
transaction { MangaMetaTable.select { (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) } }.firstOrNull() MangaMetaTable.select { (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) }
}.firstOrNull()
if (meta == null) { if (meta == null) {
MangaMetaTable.insert { MangaMetaTable.insert {
it[MangaMetaTable.key] = key it[MangaMetaTable.key] = key
@@ -155,7 +157,7 @@ object Manga {
it[MangaMetaTable.ref] = manga it[MangaMetaTable.ref] = manga
} }
} else { } else {
MangaMetaTable.update { MangaMetaTable.update({ (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) }) {
it[MangaMetaTable.value] = value it[MangaMetaTable.value] = value
} }
} }
@@ -176,7 +178,9 @@ object Manga {
?: if (!mangaEntry[MangaTable.initialized]) { ?: if (!mangaEntry[MangaTable.initialized]) {
// initialize then try again // initialize then try again
getManga(mangaId) getManga(mangaId)
transaction { MangaTable.select { MangaTable.id eq mangaId }.first() }[MangaTable.thumbnail_url]!! transaction {
MangaTable.select { MangaTable.id eq mangaId }.first()
}[MangaTable.thumbnail_url]!!
} else { } else {
// source provides no thumbnail url for this manga // source provides no thumbnail url for this manga
throw NullPointerException() throw NullPointerException()