diff --git a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs index 2d1aabf5f..23bab883e 100644 --- a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs @@ -194,7 +194,6 @@ namespace Emby.Server.Implementations.Data using (var statement = connection.PrepareStatement("select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=@ResultId")) { statement.TryBind("@ResultId", id.ToGuidParamValue()); - statement.MoveNext(); foreach (var row in statement.ExecuteQuery()) { diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 78d78a9df..f017a21dc 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -638,25 +638,30 @@ namespace Emby.Server.Implementations.Data CheckDisposed(); + var tuples = new List>>(); + foreach (var item in items) + { + var ancestorIds = item.SupportsAncestors ? + item.GetAncestorIds().Distinct().ToList() : + null; + + tuples.Add(new Tuple>(item, ancestorIds)); + } + using (var connection = CreateConnection()) { using (WriteLock.Write()) { connection.RunInTransaction(db => { - SaveItemsInTranscation(db, items); + SaveItemsInTranscation(db, tuples); }); } } } - private void SaveItemsInTranscation(IDatabaseConnection db, List items) + private void SaveItemsInTranscation(IDatabaseConnection db, List>> tuples) { - if (items == null) - { - throw new ArgumentNullException("items"); - } - var requiresReset = false; using (var saveItemStatement = db.PrepareStatement(GetSaveItemCommandText())) @@ -665,19 +670,21 @@ namespace Emby.Server.Implementations.Data { using (var updateAncestorsStatement = db.PrepareStatement("insert into AncestorIds (ItemId, AncestorId, AncestorIdText) values (@ItemId, @AncestorId, @AncestorIdText)")) { - foreach (var item in items) + foreach (var tuple in tuples) { if (requiresReset) { saveItemStatement.Reset(); } + var item = tuple.Item1; + SaveItem(item, saveItemStatement); //Logger.Debug(_saveItemCommand.CommandText); if (item.SupportsAncestors) { - UpdateAncestors(item.Id, item.GetAncestorIds().Distinct().ToList(), db, deleteAncestorsStatement, updateAncestorsStatement); + UpdateAncestors(item.Id, tuple.Item2, db, deleteAncestorsStatement, updateAncestorsStatement); } UpdateItemValues(item.Id, GetItemValuesToSave(item), db); @@ -802,7 +809,7 @@ namespace Emby.Server.Implementations.Data saveItemStatement.TryBind("@IsHD", item.IsHD); saveItemStatement.TryBind("@ExternalEtag", item.ExternalEtag); - if (item.DateLastRefreshed == default(DateTime)) + if (item.DateLastRefreshed != default(DateTime)) { saveItemStatement.TryBind("@DateLastRefreshed", item.DateLastRefreshed); } @@ -811,9 +818,9 @@ namespace Emby.Server.Implementations.Data saveItemStatement.TryBindNull("@DateLastRefreshed"); } - if (item.DateLastSaved == default(DateTime)) + if (item.DateLastSaved != default(DateTime)) { - saveItemStatement.TryBind("@DateLastSaved", item.DateLastRefreshed); + saveItemStatement.TryBind("@DateLastSaved", item.DateLastSaved); } else { @@ -948,7 +955,7 @@ namespace Emby.Server.Implementations.Data var hasSeries = item as IHasSeries; if (hasSeries != null) { - saveItemStatement.TryBind("@SeriesName", hasSeries.FindSeriesName()); + saveItemStatement.TryBind("@SeriesName", hasSeries.SeriesName); } else { @@ -960,8 +967,8 @@ namespace Emby.Server.Implementations.Data var episode = item as Episode; if (episode != null) { - saveItemStatement.TryBind("@SeasonName", episode.FindSeasonName()); - saveItemStatement.TryBind("@SeasonId", episode.FindSeasonId()); + saveItemStatement.TryBind("@SeasonName", episode.SeasonName); + saveItemStatement.TryBind("@SeasonId", episode.SeasonId); } else { @@ -971,8 +978,8 @@ namespace Emby.Server.Implementations.Data if (hasSeries != null) { - saveItemStatement.TryBind("@SeriesId", hasSeries.FindSeriesId()); - saveItemStatement.TryBind("@SeriesSortName", hasSeries.FindSeriesSortName()); + saveItemStatement.TryBind("@SeriesId", hasSeries.SeriesId); + saveItemStatement.TryBind("@SeriesSortName", hasSeries.SeriesSortName); } else { diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs index 360a2cee7..7b88be19c 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs @@ -25,10 +25,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { _cancellationToken = cancellationToken; + byte[] buffer = new byte[BufferSize]; + while (!cancellationToken.IsCancellationRequested) { - byte[] buffer = new byte[BufferSize]; - var bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false); if (bytesRead > 0) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs index 7605641b2..bd6f31906 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs @@ -19,6 +19,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts public Action OnFinished { get; set; } private readonly ILogger _logger; + private bool _isActive; public QueueStream(Stream outputStream, ILogger logger) { @@ -29,7 +30,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts public void Queue(byte[] bytes) { - _queue.Enqueue(bytes); + if (_isActive) + { + _queue.Enqueue(bytes); + } } public void Start(CancellationToken cancellationToken) @@ -57,6 +61,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { while (!cancellationToken.IsCancellationRequested) { + _isActive = true; + var bytes = Dequeue(); if (bytes != null) { @@ -83,6 +89,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } finally { + _isActive = false; + if (OnFinished != null) { OnFinished(this); diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index 0491e800f..9f8dca434 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -418,6 +418,11 @@ namespace MediaBrowser.Providers.Manager // If any remote providers changed, run them all so that priorities can be honored if (i is IRemoteMetadataProvider) { + if (options.MetadataRefreshMode == MetadataRefreshMode.ValidationOnly) + { + return false; + } + return anyRemoteProvidersChanged; } diff --git a/MediaBrowser.Providers/TV/EpisodeMetadataService.cs b/MediaBrowser.Providers/TV/EpisodeMetadataService.cs index 3de79f779..2e4271c0f 100644 --- a/MediaBrowser.Providers/TV/EpisodeMetadataService.cs +++ b/MediaBrowser.Providers/TV/EpisodeMetadataService.cs @@ -20,40 +20,39 @@ namespace MediaBrowser.Providers.TV { var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false); - if (updateType <= ItemUpdateType.None) + var seriesName = item.FindSeriesName(); + if (!string.Equals(item.SeriesName, seriesName, StringComparison.Ordinal)) { - if (!string.Equals(item.SeriesName, item.FindSeriesName(), StringComparison.Ordinal)) - { - updateType |= ItemUpdateType.MetadataImport; - } + item.SeriesName = seriesName; + updateType |= ItemUpdateType.MetadataImport; } - if (updateType <= ItemUpdateType.None) + + var seriesSortName = item.FindSeriesSortName(); + if (!string.Equals(item.SeriesSortName, seriesSortName, StringComparison.Ordinal)) { - if (!string.Equals(item.SeriesSortName, item.FindSeriesSortName(), StringComparison.Ordinal)) - { - updateType |= ItemUpdateType.MetadataImport; - } + item.SeriesSortName = seriesSortName; + updateType |= ItemUpdateType.MetadataImport; } - if (updateType <= ItemUpdateType.None) + + var seasonName = item.FindSeasonName(); + if (!string.Equals(item.SeasonName, seasonName, StringComparison.Ordinal)) { - if (!string.Equals(item.SeasonName, item.FindSeasonName(), StringComparison.Ordinal)) - { - updateType |= ItemUpdateType.MetadataImport; - } + item.SeasonName = seasonName; + updateType |= ItemUpdateType.MetadataImport; } - if (updateType <= ItemUpdateType.None) + + var seriesId = item.FindSeriesId(); + if (item.SeriesId != seriesId) { - if (item.SeriesId != item.FindSeriesId()) - { - updateType |= ItemUpdateType.MetadataImport; - } + item.SeriesId = seriesId; + updateType |= ItemUpdateType.MetadataImport; } - if (updateType <= ItemUpdateType.None) + + var seasonId = item.FindSeasonId(); + if (item.SeasonId != seasonId) { - if (item.SeasonId != item.FindSeasonId()) - { - updateType |= ItemUpdateType.MetadataImport; - } + item.SeasonId = seasonId; + updateType |= ItemUpdateType.MetadataImport; } return updateType; diff --git a/MediaBrowser.Providers/TV/SeasonMetadataService.cs b/MediaBrowser.Providers/TV/SeasonMetadataService.cs index b973620f1..81a0c0b4a 100644 --- a/MediaBrowser.Providers/TV/SeasonMetadataService.cs +++ b/MediaBrowser.Providers/TV/SeasonMetadataService.cs @@ -37,16 +37,24 @@ namespace MediaBrowser.Providers.TV updateType |= SaveIsVirtualItem(item, episodes); } - if (!string.Equals(item.SeriesName, item.FindSeriesName(), StringComparison.Ordinal)) + var seriesName = item.FindSeriesName(); + if (!string.Equals(item.SeriesName, seriesName, StringComparison.Ordinal)) { + item.SeriesName = seriesName; updateType |= ItemUpdateType.MetadataImport; } - if (!string.Equals(item.SeriesSortName, item.FindSeriesSortName(), StringComparison.Ordinal)) + + var seriesSortName = item.FindSeriesSortName(); + if (!string.Equals(item.SeriesSortName, seriesSortName, StringComparison.Ordinal)) { + item.SeriesSortName = seriesSortName; updateType |= ItemUpdateType.MetadataImport; } - if (item.SeriesId != item.FindSeriesId()) + + var seriesId = item.FindSeriesId(); + if (item.SeriesId != seriesId) { + item.SeriesId = seriesId; updateType |= ItemUpdateType.MetadataImport; }