Skip to content

Commit

Permalink
feat: add actions to purge all movie collections & show alternate ord…
Browse files Browse the repository at this point in the history
…erings
  • Loading branch information
revam committed Dec 1, 2024
1 parent 0af72dc commit 159ca4c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Shoko.Server/API/v3/Controllers/ActionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ public ActionResult PurgeAllUnusedTmdbMovies()
return Ok();
}

/// <summary>
/// Purge all unused TMDB Movie Collections.
/// </summary>
/// <returns></returns>
[HttpGet("PurgeAllUnusedTmdbMovieCollections")]
public ActionResult PurgeAllUnusedTmdbMovieCollections()
{
Task.Factory.StartNew(() => _tmdbService.PurgeAllMovieCollections());
return Ok();
}

/// <summary>
/// Update all TMDB Shows in the local database.
/// </summary>
Expand Down Expand Up @@ -213,6 +224,17 @@ public ActionResult PurgeAllUnusedTmdbShows()
return Ok();
}

/// <summary>
/// Purge all unused TMDB Show Alternate Orderings.
/// </summary>
/// <returns></returns>
[HttpGet("PurgeAllUnusedTmdbShowAlternateOrderings")]
public ActionResult PurgeAllUnusedTmdbShowAlternateOrderings()
{
Task.Factory.StartNew(() => _tmdbService.PurgeAllShowEpisodeGroups());
return Ok();
}

/// <summary>
/// Update all Trakt info. Right now, that's not much.
/// </summary>
Expand Down
34 changes: 34 additions & 0 deletions Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>([
..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
Expand Down Expand Up @@ -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<int>([
..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
Expand Down

0 comments on commit 159ca4c

Please sign in to comment.