Skip to content

Commit

Permalink
fix: fetch old episodes with long description
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Sep 12, 2024
1 parent ded4ff5 commit 1fa81ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/main/kotlin/fr/shikkanime/jobs/UpdateEpisodeJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ class UpdateEpisodeJob : AbstractJob {
needRefreshCache = true
}

if (originalEpisode.description != mapping.description && !originalEpisode.description.isNullOrBlank() && languageCacheService.detectLanguage(
originalEpisode.description
) == mapping.anime!!.countryCode!!.name.lowercase()
val trimmedDescription = originalEpisode.description?.take(Constant.MAX_DESCRIPTION_LENGTH)

if (trimmedDescription != mapping.description &&
!trimmedDescription.isNullOrBlank() &&
languageCacheService.detectLanguage(trimmedDescription) == mapping.anime!!.countryCode!!.name.lowercase()
) {
mapping.description = originalEpisode.description
logger.info("Description updated for $mappingIdentifier to ${originalEpisode.description}")
mapping.description = trimmedDescription
logger.info("Description updated for $mappingIdentifier to $trimmedDescription")
hasChanged = true
needRefreshCache = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class EpisodeVariantService : AbstractService<EpisodeVariant, EpisodeVariantRepo
number = episode.number,
duration = episode.duration,
title = episode.title,
description = episode.description,
description = episode.description?.take(Constant.MAX_DESCRIPTION_LENGTH),
image = episode.image,
).apply {
status = StringUtils.getStatus(this)
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/fr/shikkanime/utils/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object Constant {
val baseUrl: String = System.getenv("BASE_URL") ?: "http://localhost:$PORT"
val DEFAULT_IMAGE_PREVIEW = "$baseUrl/assets/img/episode_no_image_preview.jpg"
const val DEFAULT_CACHE_DURATION = 31536000 // 1 year
const val MAX_DESCRIPTION_LENGTH = 1_000

init {
abstractPlatforms.forEach {
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/fr/shikkanime/jobs/FetchOldEpisodesJobTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,16 @@ class FetchOldEpisodesJobTest {
val episodes = episodeMappingService.findAllByAnime(anime)
assertTrue(episodes.any { it.season == 1 && it.number == 13 })
}

@Test
fun `failed to fetch due to long description`() {
configService.save(Config(propertyKey = ConfigPropertyKey.LAST_FETCH_OLD_EPISODES.key, propertyValue = "2023-02-13"))
configService.save(Config(propertyKey = ConfigPropertyKey.FETCH_OLD_EPISODES_RANGE.key, propertyValue = "14"))
configService.save(Config(propertyKey = ConfigPropertyKey.FETCH_OLD_EPISODES_LIMIT.key, propertyValue = "6"))
MapCache.invalidate(Config::class.java)
crunchyrollPlatform.configuration?.availableCountries?.add(CountryCode.FR)
fetchOldEpisodesJob.run()
val animes = animeService.findAll()
animes.forEach { println(it.name) }
}
}

0 comments on commit 1fa81ad

Please sign in to comment.