From b79795af503ae126e0f5ccda7002bd95826aafdc Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Sat, 31 Dec 2022 11:36:08 -0600 Subject: [PATCH] add debug logging to local subtitle provider (#1083) --- .../Data/Repositories/MetadataRepository.cs | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ErsatzTV.Infrastructure/Data/Repositories/MetadataRepository.cs b/ErsatzTV.Infrastructure/Data/Repositories/MetadataRepository.cs index e2aeca936..b676b295b 100644 --- a/ErsatzTV.Infrastructure/Data/Repositories/MetadataRepository.cs +++ b/ErsatzTV.Infrastructure/Data/Repositories/MetadataRepository.cs @@ -4,14 +4,20 @@ using ErsatzTV.Core.Extensions; using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Infrastructure.Extensions; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; namespace ErsatzTV.Infrastructure.Data.Repositories; public class MetadataRepository : IMetadataRepository { private readonly IDbContextFactory _dbContextFactory; + private readonly ILogger _logger; - public MetadataRepository(IDbContextFactory dbContextFactory) => _dbContextFactory = dbContextFactory; + public MetadataRepository(IDbContextFactory dbContextFactory, ILogger logger) + { + _dbContextFactory = dbContextFactory; + _logger = logger; + } public async Task RemoveActor(Actor actor) { @@ -483,6 +489,11 @@ public class MetadataRepository : IMetadataRepository public async Task UpdateSubtitles(Metadata metadata, List subtitles) { + _logger.LogDebug( + "Updating {Count} subtitles; metadata is {Metadata}", + subtitles.Count, + metadata.GetType().Name); + int metadataId = metadata.Id; await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); @@ -508,6 +519,10 @@ public class MetadataRepository : IMetadataRepository _ => None }; + _logger.LogDebug( + "Existing metadata is {Metadata}", + await maybeMetadata.Map(m => m.GetType().Name).IfNoneAsync("[none]")); + foreach (Metadata existing in maybeMetadata) { var toAdd = subtitles.Filter(s => existing.Subtitles.All(es => es.StreamIndex != s.StreamIndex)).ToList(); @@ -515,6 +530,12 @@ public class MetadataRepository : IMetadataRepository .ToList(); var toUpdate = subtitles.Except(toAdd).ToList(); + _logger.LogDebug( + "Subtitles to add: {ToAdd}, to remove: {ToRemove}, to update: {ToUpdate}", + toAdd.Count, + toRemove.Count, + toUpdate.Count); + if (toAdd.Any() || toRemove.Any() || toUpdate.Any()) { // add @@ -538,14 +559,20 @@ public class MetadataRepository : IMetadataRepository existingSubtitle.DateUpdated = incomingSubtitle.DateUpdated; } - return await dbContext.SaveChangesAsync() > 0; + int count = await dbContext.SaveChangesAsync(); + + _logger.LogDebug("Subtitles update changed {Count} records in the db", count); + + return count > 0; } // nothing to do + _logger.LogDebug("Subtitle update requires no database changes"); return true; } // no metadata + _logger.LogDebug("Subtitle update failure due to missing metadata"); return false; }