Continued to improve logging and fixed a few bugs introduced by refactor

This commit is contained in:
2026-01-24 23:14:16 -07:00
parent 9e324f14a7
commit 4fc8b4799d
4 changed files with 37 additions and 42 deletions

View File

@@ -17,7 +17,6 @@ public class MovieHelper(ILogger logger)
public bool IsMovieStale(BaseItem movie) public bool IsMovieStale(BaseItem movie)
{ {
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Start of scanning for movie: {Movie}", movie); _loggingHelper.LogDebugInformation("Start of scanning for movie: {Movie}", movie);
_loggingHelper.LogDebugInformation("-------------------------------------------------"); _loggingHelper.LogDebugInformation("-------------------------------------------------");
@@ -41,19 +40,22 @@ public class MovieHelper(ILogger logger)
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff)) if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
{ {
_loggingHelper.LogDebugInformation("Most recent user data last played date is outside of cutoff. Adding {Movie} to stale movies.", movie); _loggingHelper.LogDebugInformation("Most recent user data has last played date that is outside of cutoff.");
_loggingHelper.LogDebugInformation("Adding {Movie} to stale movies.", movie);
_loggingHelper.LogDebugInformation("With Last Played Date: {LastPlayedDate}", mostRecentUserData.LastPlayedDate);
movieIsStale = true; movieIsStale = true;
} }
} }
else if (createdOutsideCutoff) else if (createdOutsideCutoff)
{ {
_loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}. Adding {Movie} to stale movies.", [movie.DateCreated, movie]); _loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}.", movie.DateCreated);
_loggingHelper.LogDebugInformation("Adding {Movie} to stale movies.", movie);
movieIsStale = true; movieIsStale = true;
} }
_loggingHelper.LogDebugInformation("-------------------------------------------------"); _loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie); _loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
return movieIsStale; return movieIsStale;
} }

View File

@@ -28,8 +28,13 @@ public class SeriesHelper(ILogger logger)
var staleCreationDate = episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff); var staleCreationDate = episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
var hasUserDataWithLastPlayedDate = episode.UserData.Any(data => data.LastPlayedDate != null); var hasUserDataWithLastPlayedDate = episode.UserData.Any(data => data.LastPlayedDate != null);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Debug data for episode: {Episode}", episode);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
if (staleCreationDate && !hasUserDataWithLastPlayedDate){ if (staleCreationDate && !hasUserDataWithLastPlayedDate){
_loggingHelper.LogInformation("Creation date is stale, and no user data for episode {Episode}.", episode); _loggingHelper.LogDebugInformation("Creation date is stale, and no user data for episode {Episode}.", episode);
_loggingHelper.LogDebugInformation("Date created: {DateCreated}", episode.DateCreated);
episodeIsStale = true; episodeIsStale = true;
} }
@@ -38,9 +43,6 @@ public class SeriesHelper(ILogger logger)
.OrderByDescending(data => data.LastPlayedDate) .OrderByDescending(data => data.LastPlayedDate)
.First(); .First();
_loggingHelper.LogDebugInformation("User data for episode: {Episode}", episode);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
foreach (var property in typeof(UserData).GetProperties()) foreach (var property in typeof(UserData).GetProperties())
{ {
_loggingHelper.LogDebugInformation("{PropertyName}: {PropertyValue}", property.Name, property.GetValue(mostRecentUserData)); _loggingHelper.LogDebugInformation("{PropertyName}: {PropertyValue}", property.Name, property.GetValue(mostRecentUserData));
@@ -54,7 +56,7 @@ public class SeriesHelper(ILogger logger)
{ {
episodeIsStale = true; episodeIsStale = true;
_loggingHelper.LogDebugInformation("Most recent user data has a last played date of: {LastPlayedDate}.", [mostRecentUserData.LastPlayedDate]); _loggingHelper.LogDebugInformation("Most recent user data has a last played date of: {LastPlayedDate}.", [mostRecentUserData.LastPlayedDate]);
_loggingHelper.LogDebugInformation("And episode created {DateCreated}.", episode.DateCreated); _loggingHelper.LogDebugInformation("Episode created {DateCreated}.", episode.DateCreated);
_loggingHelper.LogDebugInformation("Episode is marked as stale."); _loggingHelper.LogDebugInformation("Episode is marked as stale.");
} }
} }
@@ -79,6 +81,8 @@ public class SeriesHelper(ILogger logger)
if(staleEpisodes.Count == episodes.Count) if(staleEpisodes.Count == episodes.Count)
{ {
seasonIsStale = true; seasonIsStale = true;
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Stale episodes count matches season episode count. Season is stale."); _loggingHelper.LogDebugInformation("Stale episodes count matches season episode count. Season is stale.");
_loggingHelper.LogDebugInformation("-------------------------------------------------"); _loggingHelper.LogDebugInformation("-------------------------------------------------");
} }

View File

@@ -22,9 +22,5 @@ public class SeriesInfo
/// <summary> /// <summary>
/// Gets or sets seasons. /// Gets or sets seasons.
/// </summary> /// </summary>
#pragma warning disable CA2227 // Collection properties should be read only public IEnumerable<string> Seasons { get; set; } = [];
#pragma warning disable CA1002 // Do not expose generic lists
public List<string> Seasons { get; set; } = [];
#pragma warning restore CA1002 // Do not expose generic lists
#pragma warning restore CA2227 // Collection properties should be read only
} }

View File

@@ -83,9 +83,8 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogInformation("Starting scan of series items."); _loggingHelper.LogInformation("Starting scan of series items.");
_loggingHelper.LogInformation("-------------------------------------------------"); _loggingHelper.LogInformation("-------------------------------------------------");
List<BaseItem> staleEpisodes = [.. series.SelectMany(GetStaleEpisodes)]; List<BaseItem> staleSeasons = [.. series.SelectMany(GetStaleSeasons)];
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Starting scan of movies items."); _loggingHelper.LogInformation("Starting scan of movies items.");
_loggingHelper.LogInformation("-------------------------------------------------"); _loggingHelper.LogInformation("-------------------------------------------------");
@@ -103,13 +102,13 @@ public sealed class StaleMediaTask : IScheduledTask
} }
_loggingHelper.LogInformation("-------------------------------------------------"); _loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Stale Episodes found: {StaleEpisodes}", staleEpisodes.Count); _loggingHelper.LogInformation("Stale seasons found: {StaleSeasons}", staleSeasons.Count);
if (staleEpisodes.Count > 0 && Configuration.DebugMode) if (staleSeasons.Count > 0 && Configuration.DebugMode)
{ {
List<SeriesInfo> seriesInfoList = FindSeriesInfoFromEpisodes(staleEpisodes); IEnumerable<SeriesInfo> staleSeriesInfo = FindSeriesInfo(staleSeasons);
foreach (var seriesInfo in seriesInfoList) foreach (var seriesInfo in staleSeriesInfo)
{ {
_loggingHelper.LogDebugInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]); _loggingHelper.LogDebugInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
} }
@@ -132,9 +131,8 @@ public sealed class StaleMediaTask : IScheduledTask
} }
private List<BaseItem> GetStaleEpisodes(BaseItem item) private List<BaseItem> GetStaleSeasons(BaseItem item)
{ {
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Debug data for series: {SeriesName}", item.Name); _loggingHelper.LogDebugInformation("Debug data for series: {SeriesName}", item.Name);
_loggingHelper.LogDebugInformation("-------------------------------------------------"); _loggingHelper.LogDebugInformation("-------------------------------------------------");
@@ -145,7 +143,7 @@ public sealed class StaleMediaTask : IScheduledTask
Recursive = false Recursive = false
}); });
List<BaseItem> staleEpisodes = [ ..seasons List<BaseItem> staleSeasons = [ ..seasons
.Where(season => { .Where(season => {
var episodes = _libraryManager.GetItemList(new InternalItemsQuery var episodes = _libraryManager.GetItemList(new InternalItemsQuery
{ {
@@ -155,43 +153,38 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season); _loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season);
return _seriesHelper.IsSeasonDataStale(episodes); bool isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
_loggingHelper.LogDebugInformation("End of season debug information for {SeasonNumber}.", season);
return isSeasonDataStale;
})]; })];
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item); _loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item);
_loggingHelper.LogDebugInformation("-------------------------------------------------"); _loggingHelper.LogDebugInformation("-------------------------------------------------");
return staleEpisodes; return staleSeasons;
} }
private List<SeriesInfo> FindSeriesInfoFromEpisodes(IReadOnlyCollection<BaseItem> episodes) private IEnumerable<SeriesInfo> FindSeriesInfo(IReadOnlyCollection<BaseItem> seasons)
{ {
Guid[] seasonIds = [.. episodes.Select(episode => episode.ParentId).Distinct()];
var seasons = _libraryManager.GetItemList(new InternalItemsQuery
{
ItemIds = seasonIds
});
Guid[] seriesIds = [.. seasons.Select(season => season.ParentId).Distinct()]; Guid[] seriesIds = [.. seasons.Select(season => season.ParentId).Distinct()];
var series = _libraryManager.GetItemList(new InternalItemsQuery IReadOnlyCollection<BaseItem> series = _libraryManager.GetItemList(new InternalItemsQuery
{ {
ItemIds = seriesIds ItemIds = seriesIds
}).ToList(); });
List<string> seriesNames = [.. series.Select(series => series.Name).Distinct()]; IEnumerable<SeriesInfo> seriesInfoList = series.Select(series =>
List<SeriesInfo> seriesInfoList = [];
series.ForEach(series =>
{ {
seriesInfoList.Add(new SeriesInfo return new SeriesInfo
{ {
Id = series.Id, Id = series.Id,
SeriesName = series.Name, SeriesName = series.Name,
Seasons = [.. seasons.Where(season => season.ParentId == series.Id).Select(season => season.Name)] Seasons = [.. seasons.Where(season => season.ParentId == series.Id).Select(season => season.Name)]
}); };
}); });
return seriesInfoList; return seriesInfoList;