diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-08-27 15:53:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-27 15:53:08 -0400 |
| commit | 6c156ce841eb530ddb2deca29bad948c73e84194 (patch) | |
| tree | d164c774a57291a1149288e60b65b96ec9706624 /MediaBrowser.Server.Implementations/Persistence | |
| parent | a8fb422fe47a46e4ad546a96b7263cfa7fec5ffd (diff) | |
| parent | 633cdb99c2251711b73bb5cb6dca709b4497baed (diff) | |
Merge pull request #2112 from MediaBrowser/beta
Beta
Diffstat (limited to 'MediaBrowser.Server.Implementations/Persistence')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs | 94 |
1 files changed, 9 insertions, 85 deletions
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 5c94d589d..5ece3dd82 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -92,7 +92,6 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _deleteImagesCommand; private IDbCommand _saveImagesCommand; - private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; public const int LatestSchemaVersion = 109; @@ -412,7 +411,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "SeasonId", "SeriesId", "SeriesSortName", - "PresentationUniqueKey" + "PresentationUniqueKey", + "InheritedParentalRatingValue" }; private readonly string[] _mediaStreamSaveColumns = @@ -611,11 +611,6 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveStreamCommand.Parameters.Add(_saveStreamCommand, "@" + col); } - _updateInheritedRatingCommand = _connection.CreateCommand(); - _updateInheritedRatingCommand.CommandText = "Update TypedBaseItems set InheritedParentalRatingValue=@InheritedParentalRatingValue where Guid=@Guid"; - _updateInheritedRatingCommand.Parameters.Add(_updateInheritedRatingCommand, "@Guid"); - _updateInheritedRatingCommand.Parameters.Add(_updateInheritedRatingCommand, "@InheritedParentalRatingValue"); - _updateInheritedTagsCommand = _connection.CreateCommand(); _updateInheritedTagsCommand.CommandText = "Update TypedBaseItems set InheritedTags=@InheritedTags where Guid=@Guid"; _updateInheritedTagsCommand.Parameters.Add(_updateInheritedTagsCommand, "@Guid"); @@ -942,7 +937,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.Album; - _saveItemCommand.GetParameter(index++).Value = item.IsVirtualItem || (!item.IsFolder && item.LocationType == LocationType.Virtual); + _saveItemCommand.GetParameter(index++).Value = item.IsVirtualItem; var hasSeries = item as IHasSeries; if (hasSeries != null) @@ -1458,6 +1453,12 @@ namespace MediaBrowser.Server.Implementations.Persistence } index++; + if (!reader.IsDBNull(index)) + { + item.InheritedParentalRatingValue = reader.GetInt32(index); + } + index++; + return item; } @@ -3402,7 +3403,6 @@ namespace MediaBrowser.Server.Implementations.Persistence public async Task UpdateInheritedValues(CancellationToken cancellationToken) { - await UpdateInheritedParentalRating(cancellationToken).ConfigureAwait(false); await UpdateInheritedTags(cancellationToken).ConfigureAwait(false); } @@ -3482,82 +3482,6 @@ namespace MediaBrowser.Server.Implementations.Persistence } } - private async Task UpdateInheritedParentalRating(CancellationToken cancellationToken) - { - var newValues = new List<Tuple<Guid, int>>(); - - using (var cmd = _connection.CreateCommand()) - { - cmd.CommandText = "select Guid,InheritedParentalRatingValue,(select Max(InheritedParentalRatingValue, (select COALESCE(MAX(InheritedParentalRatingValue),0) from TypedBaseItems where guid in (Select AncestorId from AncestorIds where ItemId=Outer.guid)))) as NewInheritedParentalRatingValue from typedbaseitems as Outer where InheritedParentalRatingValue <> NewInheritedParentalRatingValue"; - - using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) - { - while (reader.Read()) - { - var id = reader.GetGuid(0); - var newValue = reader.GetInt32(2); - - newValues.Add(new Tuple<Guid, int>(id, newValue)); - } - } - } - - Logger.Debug("UpdateInheritedParentalRatings - {0} rows", newValues.Count); - if (newValues.Count == 0) - { - return; - } - - await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); - - IDbTransaction transaction = null; - - try - { - transaction = _connection.BeginTransaction(); - - foreach (var item in newValues) - { - _updateInheritedRatingCommand.GetParameter(0).Value = item.Item1; - _updateInheritedRatingCommand.GetParameter(1).Value = item.Item2; - - _updateInheritedRatingCommand.Transaction = transaction; - _updateInheritedRatingCommand.ExecuteNonQuery(); - } - - transaction.Commit(); - } - catch (OperationCanceledException) - { - if (transaction != null) - { - transaction.Rollback(); - } - - throw; - } - catch (Exception e) - { - Logger.ErrorException("Error running query:", e); - - if (transaction != null) - { - transaction.Rollback(); - } - - throw; - } - finally - { - if (transaction != null) - { - transaction.Dispose(); - } - - WriteLock.Release(); - } - } - private static Dictionary<string, string[]> GetTypeMapDictionary() { var dict = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase); |
