diff --git a/Shoko.Server/Filters/FilterExtensions.cs b/Shoko.Server/Filters/FilterExtensions.cs index 48b1e1c75..1a9e9357b 100644 --- a/Shoko.Server/Filters/FilterExtensions.cs +++ b/Shoko.Server/Filters/FilterExtensions.cs @@ -196,7 +196,7 @@ public static Filterable ToFilterable(this SVR_AnimeGroup group) MissingEpisodesDelegate = () => group.MissingEpisodeCount, MissingEpisodesCollectingDelegate = () => - group.MissingEpisodeCount, + group.MissingEpisodeCountGroups, TagsDelegate = () => group.Tags.Select(a => a.TagName).ToHashSet(), CustomTagsDelegate = () => diff --git a/Shoko.Server/Services/AnimeSeriesService.cs b/Shoko.Server/Services/AnimeSeriesService.cs index 909a067fd..ef7889f5c 100644 --- a/Shoko.Server/Services/AnimeSeriesService.cs +++ b/Shoko.Server/Services/AnimeSeriesService.cs @@ -596,7 +596,7 @@ private void UpdateMissingEpisodeStats(SVR_AnimeSeries series, List b.GroupID); } - ).ToList(); + ).Distinct().ToList(); var videoLocals = eps.Where(a => a.EpisodeTypeEnum == EpisodeType.Episode).SelectMany(a => a.VideoLocals.Select(b => new @@ -610,13 +610,40 @@ private void UpdateMissingEpisodeStats(SVR_AnimeSeries series, List a.EpisodeTypeEnum == EpisodeType.Episode).ForAll(ep => { var aniEp = ep.AniDB_Episode; - // Un-aired episodes should not be included in the stats. if (aniEp is not { HasAired: true }) return; - var vids = videoLocals[ep.AniDB_EpisodeID].ToList(); - var thisEpNum = aniEp.EpisodeNumber; + // does this episode have a file released + var epReleased = false; + // does this episode have a file released by the group the user is collecting + var epReleasedGroup = false; + + if (grpStatuses.Count == 0) + { + // If there are no group statuses, the UDP command has not been run yet or has failed + // The current has aired, as un-aired episodes are filtered out above + epReleased = true; + // We do not set epReleasedGroup here because we have no way to know + } + else + { + // Get all groups which have their status set to complete or finished or have released this episode + var filteredGroups = grpStatuses + .Where( + a => a.CompletionState is (int)Group_CompletionStatus.Complete or (int)Group_CompletionStatus.Finished + || a.HasGroupReleasedEpisode(thisEpNum)) + .ToList(); + // Episode is released if any of the groups have released it + epReleased = filteredGroups.Count > 0; + // Episode is released by one of the groups user is collecting if one of the userReleaseGroups is included in filteredGroups + epReleasedGroup = filteredGroups.Any(a => userReleaseGroups.Contains(a.GroupID)); + } + + // If epReleased is false, then we consider the episode to be not released even if it has aired as no group has released it + if (!epReleased) return; + + var vids = videoLocals[ep.AniDB_EpisodeID].ToList(); if (thisEpNum > latestLocalEpNumber && vids.Any()) { @@ -626,7 +653,7 @@ private void UpdateMissingEpisodeStats(SVR_AnimeSeries series, List 0); } + // Skip adding to epGroupReleasedList if the episode has not been released by one of the groups user is collecting + if (!epReleasedGroup) return; + lock (epGroupReleasedList) { - epGroupReleasedList.Add(ep, epReleasedGroup || vids.Any()); + epGroupReleasedList.Add(ep, vids.Count > 0); } } catch (Exception e)