diff --git a/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt b/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt index 036568c..db10462 100644 --- a/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt +++ b/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt @@ -3,12 +3,10 @@ package fr.ziedelth.controllers import com.google.inject.Inject import fr.ziedelth.entities.Anime import fr.ziedelth.entities.isNullOrNotValid -import fr.ziedelth.repositories.AnimeRepository -import fr.ziedelth.repositories.CountryRepository -import fr.ziedelth.repositories.EpisodeRepository -import fr.ziedelth.repositories.SimulcastRepository +import fr.ziedelth.repositories.* import fr.ziedelth.services.AnimeService import fr.ziedelth.services.EpisodeService +import fr.ziedelth.services.ProfileService import fr.ziedelth.utils.ImageCache import fr.ziedelth.utils.Logger import fr.ziedelth.utils.routes.Authorized @@ -43,6 +41,12 @@ class AnimeController : AttachmentController("/animes") { @Inject private lateinit var simulcastRepository: SimulcastRepository + @Inject + private lateinit var profileRepository: ProfileRepository + + @Inject + private lateinit var profileService: ProfileService + @Path("/country/{country}/search/hash/{hash}") @Get private fun searchByCountryAndHash(country: String, hash: String): Response { @@ -149,6 +153,10 @@ class AnimeController : AttachmentController("/animes") { savedAnime = animeRepository.save(savedAnime) animeService.invalidateAll() episodeService.invalidateAll() + + val profiles = profileRepository.findProfilesWithAnime(anime.uuid) + profiles.forEach { profileService.invalidateProfile(it) } + return Response.ok(savedAnime) } diff --git a/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt b/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt index 9356254..11e346c 100644 --- a/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt +++ b/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt @@ -8,6 +8,7 @@ import fr.ziedelth.events.EpisodesReleaseEvent import fr.ziedelth.repositories.* import fr.ziedelth.services.AnimeService import fr.ziedelth.services.EpisodeService +import fr.ziedelth.services.ProfileService import fr.ziedelth.services.SimulcastService import fr.ziedelth.utils.CalendarConverter import fr.ziedelth.utils.ImageCache @@ -52,6 +53,12 @@ class EpisodeController : AttachmentController("/episodes") { @Inject private lateinit var episodeService: EpisodeService + @Inject + private lateinit var profileRepository: ProfileRepository + + @Inject + private lateinit var profileService: ProfileService + @Path("/country/{country}/page/{page}/limit/{limit}") @Get private fun paginationByCountry(country: String, page: Int, limit: Int): Response { @@ -147,6 +154,10 @@ class EpisodeController : AttachmentController("/episodes") { animeService.invalidateAll() simulcastService.invalidateAll() + val animes = savedEpisodes.mapNotNull { it.anime?.uuid }.distinct() + val profiles = animes.flatMap { profileRepository.findProfilesWithAnime(it) }.distinct() + profiles.forEach { profileService.invalidateProfile(it) } + if (savedEpisodes.size <= 5) { Thread { PluginManager.callEvent(EpisodesReleaseEvent(savedEpisodes)) @@ -189,6 +200,10 @@ class EpisodeController : AttachmentController("/episodes") { savedEpisode = episodeRepository.save(savedEpisode) episodeService.invalidateAll() + + val profiles = profileRepository.findProfilesWithAnime(savedEpisode.anime!!.uuid) + profiles.forEach { profileService.invalidateProfile(it) } + return Response.ok(savedEpisode) } } diff --git a/src/main/kotlin/fr/ziedelth/repositories/ProfileRepository.kt b/src/main/kotlin/fr/ziedelth/repositories/ProfileRepository.kt index cc30eb5..c314540 100644 --- a/src/main/kotlin/fr/ziedelth/repositories/ProfileRepository.kt +++ b/src/main/kotlin/fr/ziedelth/repositories/ProfileRepository.kt @@ -28,6 +28,19 @@ class ProfileRepository : AbstractRepository() { } } + fun findProfilesWithAnime(animeUuid: UUID): List { + return database.inReadOnlyTransaction { + it.createQuery( + """ + SELECT DISTINCT pa.profile.uuid + FROM ProfileAnime pa + WHERE pa.anime.uuid = :animeUuid + """.trimIndent(), + UUID::class.java + ).setParameter("animeUuid", animeUuid).resultList + } + } + /** * Saves the provided filter data and returns the saved profile. *