Skip to content

Commit

Permalink
Merge pull request #427 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ziedelth authored May 1, 2024
2 parents 1b4eacb + 923802d commit 247a667
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/main/kotlin/fr/shikkanime/controllers/admin/AdminController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package fr.shikkanime.controllers.admin
import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.TokenDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.EpisodeMapping
import fr.shikkanime.entities.EpisodeVariant
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.enums.Link
import fr.shikkanime.services.*
import fr.shikkanime.services.caches.SimulcastCacheService
import fr.shikkanime.utils.MapCache
import fr.shikkanime.utils.routes.AdminSessionAuthenticated
import fr.shikkanime.utils.routes.Controller
import fr.shikkanime.utils.routes.Path
Expand Down Expand Up @@ -109,6 +114,12 @@ class AdminController {
@AdminSessionAuthenticated
private fun invalidateSimulcasts(): Response {
animeService.recalculateSimulcasts()
MapCache.invalidate(
Anime::class.java,
EpisodeMapping::class.java,
EpisodeVariant::class.java,
Simulcast::class.java
)
return Response.redirect(Link.DASHBOARD.href)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ enum class ConfigPropertyKey(val key: String) {
TRANSLATE_CALENDAR("translate_calendar"),
LAST_FETCH_OLD_EPISODES("last_fetch_old_episodes"),
FETCH_OLD_EPISODES_RANGE("fetch_old_episodes_range"),
FETCH_OLD_EPISODES_LIMIT("fetch_old_episodes_limit"),
}
8 changes: 6 additions & 2 deletions src/main/kotlin/fr/shikkanime/jobs/FetchOldEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class FetchOldEpisodesJob : AbstractJob {
@Inject
private lateinit var configService: ConfigService

@Inject
private lateinit var configCacheService: ConfigCacheService

@Inject
private lateinit var episodeCacheService: ConfigCacheService

Expand Down Expand Up @@ -80,9 +83,10 @@ class FetchOldEpisodesJob : AbstractJob {

episodes.removeIf { it.releaseDateTime.toLocalDate() !in dates }

val limit = configCacheService.getValueAsInt(ConfigPropertyKey.FETCH_OLD_EPISODES_LIMIT, 5)
episodes.groupBy { it.anime + it.releaseDateTime.toLocalDate().toString() }.forEach { (_, animeDayEpisodes) ->
if (animeDayEpisodes.size > 5) {
logger.warning("More than 5 episodes for ${animeDayEpisodes.first().anime} on ${animeDayEpisodes.first().releaseDateTime.toLocalDate()}, removing...")
if (animeDayEpisodes.size > limit) {
logger.warning("More than $limit episodes for ${animeDayEpisodes.first().anime} on ${animeDayEpisodes.first().releaseDateTime.toLocalDate()}, removing...")
episodes.removeAll(animeDayEpisodes)
return@forEach
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/db/changelog/2024/05/01-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<property global="false" name="id" value="1714568857833"/>
<property global="false" name="author" value="Ziedelth"/>

<changeSet id="${id}-1" author="${author}" dbms="postgresql">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">SELECT COUNT(*)
FROM config
WHERE property_key = 'fetch_old_episodes_limit'</sqlCheck>
</preConditions>

<insert tableName="config">
<column name="uuid" valueComputed="gen_random_uuid()"/>
<column name="property_key" value="fetch_old_episodes_limit"/>
<column name="property_value" value="8"/>
</insert>
</changeSet>
</databaseChangeLog>
2 changes: 2 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@
<include file="/db/changelog/2024/04/06-changelog.xml"/>
<include file="/db/changelog/2024/04/07-changelog.xml"/>
<include file="/db/changelog/2024/04/08-changelog.xml"/>
<!-- May 2024 -->
<include file="/db/changelog/2024/05/01-changelog.xml"/>
</databaseChangeLog>

0 comments on commit 247a667

Please sign in to comment.