Skip to content

Commit

Permalink
Merge pull request #444 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Fix condition in FetchOldEpisodesJob.kt
  • Loading branch information
Ziedelth authored May 6, 2024
2 parents 021714d + f21aaff commit 3d67038
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/main/kotlin/fr/shikkanime/jobs/FetchOldEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,38 @@ class FetchOldEpisodesJob : AbstractJob {
}
}

if (realSaved == 0) {
logger.info("No new episodes found")
return
}

logger.info("Saved $realSaved episodes")
logger.info("Updating mappings...")

variants.groupBy { it.mapping!!.uuid }.forEach { (mappingUuid, variants) ->
val mapping = episodeMappingService.find(mappingUuid) ?: return@forEach
mapping.releaseDateTime = variants.minOf { it.releaseDateTime }
mapping.lastReleaseDateTime = variants.maxOf { it.releaseDateTime }
episodeMappingService.update(mapping)
}
if (realSaved > 0) {
logger.info("Updating mappings...")

logger.info("Updating animes...")
variants.groupBy { it.mapping!!.uuid }.forEach { (mappingUuid, variants) ->
val mapping = episodeMappingService.find(mappingUuid) ?: return@forEach
mapping.releaseDateTime = variants.minOf { it.releaseDateTime }
mapping.lastReleaseDateTime = variants.maxOf { it.releaseDateTime }
episodeMappingService.update(mapping)
}

logger.info("Updating animes...")

variants.groupBy { it.mapping!!.anime!!.uuid }.forEach { (animeUuid, variants) ->
val anime = animeService.find(animeUuid) ?: return@forEach
logger.info("Updating ${StringUtils.getShortName(anime.name!!)}...")
anime.releaseDateTime = variants.minOf { it.releaseDateTime }
anime.lastReleaseDateTime = variants.maxOf { it.releaseDateTime }
animeService.update(anime)
}

variants.groupBy { it.mapping!!.anime!!.uuid }.forEach { (animeUuid, variants) ->
val anime = animeService.find(animeUuid) ?: return@forEach
logger.info("Updating ${StringUtils.getShortName(anime.name!!)}...")
anime.releaseDateTime = variants.minOf { it.releaseDateTime }
anime.lastReleaseDateTime = variants.maxOf { it.releaseDateTime }
animeService.update(anime)
logger.info("Updating simulcasts...")
animeService.recalculateSimulcasts()
MapCache.invalidate(
Anime::class.java,
EpisodeMapping::class.java,
EpisodeVariant::class.java,
Simulcast::class.java
)
}

logger.info("Updating simulcasts...")
animeService.recalculateSimulcasts()
MapCache.invalidate(
Anime::class.java,
EpisodeMapping::class.java,
EpisodeVariant::class.java,
Simulcast::class.java
)
logger.info("Updating config to the next fetch date...")
config.propertyValue = from.toString()
configService.update(config)
Expand Down

0 comments on commit 3d67038

Please sign in to comment.