Skip to content

Commit

Permalink
Delete outdated thumbnails when inserting mangas into database (#739)
Browse files Browse the repository at this point in the history
In case the database got deleted without deleting cached/downloaded thumbnails, the next time a manga gets inserted, it's possible that a thumbnail was already downloaded for its id.
This then causes mangas to be displayed with incorrect thumbnails due to using the outdated cached/downloaded thumbnails
  • Loading branch information
schroda authored Oct 29, 2023
1 parent 05707e2 commit 6531b80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ object Manga {
return fetchMangaThumbnail(mangaId)
}

private fun clearThumbnail(mangaId: Int) {
fun clearThumbnail(mangaId: Int) {
val fileName = mangaId.toString()

clearCachedImage(applicationDirs.tempThumbnailCacheRoot, fileName)
Expand Down
33 changes: 21 additions & 12 deletions server/src/main/kotlin/suwayomi/tachidesk/manga/impl/MangaList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,26 @@ object MangaList {
(MangaTable.url eq manga.url) and (MangaTable.sourceReference eq sourceId)
}.firstOrNull()
if (mangaEntry == null) { // create manga entry
MangaTable.insertAndGetId {
it[url] = manga.url
it[title] = manga.title
val mangaId =
MangaTable.insertAndGetId {
it[url] = manga.url
it[title] = manga.title

it[artist] = manga.artist
it[author] = manga.author
it[description] = manga.description
it[genre] = manga.genre
it[status] = manga.status
it[thumbnail_url] = manga.thumbnail_url
it[updateStrategy] = manga.update_strategy.name
it[artist] = manga.artist
it[author] = manga.author
it[description] = manga.description
it[genre] = manga.genre
it[status] = manga.status
it[thumbnail_url] = manga.thumbnail_url
it[updateStrategy] = manga.update_strategy.name

it[sourceReference] = sourceId
}.value
it[sourceReference] = sourceId
}.value

// delete thumbnail in case cached data still exists
Manga.clearThumbnail(mangaId)

mangaId
} else {
mangaEntry[MangaTable.id].value
}
Expand Down Expand Up @@ -103,6 +109,9 @@ object MangaList {
it[sourceReference] = sourceId
}.value

// delete thumbnail in case cached data still exists
Manga.clearThumbnail(mangaId)

mangaEntry =
MangaTable.select {
(MangaTable.url eq manga.url) and (MangaTable.sourceReference eq sourceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import suwayomi.tachidesk.manga.impl.Category
import suwayomi.tachidesk.manga.impl.CategoryManga
import suwayomi.tachidesk.manga.impl.Manga.clearThumbnail
import suwayomi.tachidesk.manga.impl.backup.models.Chapter
import suwayomi.tachidesk.manga.impl.backup.models.Manga
import suwayomi.tachidesk.manga.impl.backup.models.Track
Expand Down Expand Up @@ -188,6 +189,9 @@ object ProtoBackupImport : ProtoBackupBase() {
it[inLibraryAt] = TimeUnit.MILLISECONDS.toSeconds(manga.date_added)
}.value

// delete thumbnail in case cached data still exists
clearThumbnail(mangaId)

// insert chapter data
val chaptersLength = chapters.size
chapters.forEach { chapter ->
Expand Down

0 comments on commit 6531b80

Please sign in to comment.