Skip to content

Commit

Permalink
fix: remove image not in database
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Sep 12, 2024
1 parent ded4ff5 commit f30ca03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ class AdminController {
@Inject
private lateinit var animeService: AnimeService

@Inject
private lateinit var episodeMappingService: EpisodeMappingService

@Inject
private lateinit var episodeVariantService: EpisodeVariantService

@Path
@Get
private fun home(@QueryParam("error") error: String?): Response {
Expand Down
22 changes: 22 additions & 0 deletions src/main/kotlin/fr/shikkanime/services/ImageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,28 @@ object ImageService {
get() = toHumanReadable(cache.toList().sumOf { it.size })

fun invalidate() {
Constant.injector.getInstance(Database::class.java).entityManager.use {
val query = it.createNativeQuery(
"""
SELECT uuid
FROM anime
UNION
SELECT uuid
FROM episode_mapping
UNION
SELECT uuid
FROM member
""",
UUID::class.java
)

val uuids = (query.resultList as List<UUID>) // NOSONAR
.map { uuid -> uuid.toString() }
.toSet()

cache.removeIf { img -> img.uuid !in uuids }
}

addAll(true)
}

Expand Down

0 comments on commit f30ca03

Please sign in to comment.