diff --git a/Shoko.Server/API/v3/Controllers/ActionController.cs b/Shoko.Server/API/v3/Controllers/ActionController.cs
index 6b31cbf96..fb0bc0944 100644
--- a/Shoko.Server/API/v3/Controllers/ActionController.cs
+++ b/Shoko.Server/API/v3/Controllers/ActionController.cs
@@ -181,6 +181,17 @@ public ActionResult PurgeAllUnusedTmdbMovies()
return Ok();
}
+ ///
+ /// Purge all unused TMDB Movie Collections.
+ ///
+ ///
+ [HttpGet("PurgeAllUnusedTmdbMovieCollections")]
+ public ActionResult PurgeAllUnusedTmdbMovieCollections()
+ {
+ Task.Factory.StartNew(() => _tmdbService.PurgeAllMovieCollections());
+ return Ok();
+ }
+
///
/// Update all TMDB Shows in the local database.
///
@@ -213,6 +224,17 @@ public ActionResult PurgeAllUnusedTmdbShows()
return Ok();
}
+ ///
+ /// Purge all unused TMDB Show Alternate Orderings.
+ ///
+ ///
+ [HttpGet("PurgeAllUnusedTmdbShowAlternateOrderings")]
+ public ActionResult PurgeAllUnusedTmdbShowAlternateOrderings()
+ {
+ Task.Factory.StartNew(() => _tmdbService.PurgeAllShowEpisodeGroups());
+ return Ok();
+ }
+
///
/// Update all Trakt info. Right now, that's not much.
///
diff --git a/Shoko.Server/Providers/TMDB/TmdbMetadataService.cs b/Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
index eb11cce51..10d62da0f 100644
--- a/Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
+++ b/Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
@@ -882,6 +882,21 @@ private void PurgeMovieCollection(int collectionId, bool removeImageFiles = true
}
}
+ public void PurgeAllMovieCollections(bool removeImageFiles = true)
+ {
+ var collections = _tmdbCollections.GetAll();
+ var collectionXRefs = _xrefTmdbCollectionMovies.GetAll();
+ var collectionIDs = new HashSet([
+ ..collections.Select(x => x.TmdbCollectionID),
+ ..collectionXRefs.Select(x => x.TmdbCollectionID),
+ ]);
+
+ _logger.LogInformation("Removing {Count} movie collections to be purged.", collectionIDs.Count);
+
+ foreach (var collectionID in collectionIDs)
+ PurgeMovieCollection(collectionID, removeImageFiles);
+ }
+
#endregion
#endregion
@@ -1767,6 +1782,25 @@ private void PurgeShowEpisodeGroups(int showId)
_tmdbAlternateOrdering.Delete(orderings);
}
+ public void PurgeAllShowEpisodeGroups()
+ {
+ _logger.LogInformation("Purging all show episode groups.");
+
+ var episodes = _tmdbAlternateOrderingEpisodes.GetAll();
+ var seasons = _tmdbAlternateOrderingSeasons.GetAll();
+ var orderings = _tmdbAlternateOrdering.GetAll();
+ var shows = new HashSet([
+ ..episodes.Select(e => e.TmdbShowID),
+ ..seasons.Select(s => s.TmdbShowID),
+ ..orderings.Select(o => o.TmdbShowID),
+ ]);
+
+ _logger.LogDebug("Removing {EpisodeCount} episodes and {SeasonCount} seasons across {OrderingCount} alternate orderings for {ShowCount} shows.", episodes.Count, seasons.Count, orderings.Count, shows.Count);
+ _tmdbAlternateOrderingEpisodes.Delete(episodes);
+ _tmdbAlternateOrderingSeasons.Delete(seasons);
+ _tmdbAlternateOrdering.Delete(orderings);
+ }
+
#endregion
#endregion