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 e648e1e
Show file tree
Hide file tree
Showing 2 changed files with 27 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
27 changes: 27 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,33 @@ 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()

// Calculate the difference between the cache and the UUIDs
val difference = cache.filter { img -> img.uuid !in uuids }
logger.warning("Removing ${difference.size} images from cache, not found in database")
logger.warning("${toHumanReadable(difference.sumOf { img -> img.size })} will be freed")

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

addAll(true)
}

Expand Down

0 comments on commit e648e1e

Please sign in to comment.