From cf0d9883c6eec06fa8d065e585081716520e56e4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 25 Jun 2016 01:16:54 -0400 Subject: [PATCH] fix userdata transactions --- MediaBrowser.Api/Movies/TrailersService.cs | 2 +- MediaBrowser.Model/Dlna/StreamBuilder.cs | 10 +++---- MediaBrowser.Model/Entities/MediaStream.cs | 30 +++++++++++++++++++ .../Library/MediaSourceManager.cs | 8 ----- .../Persistence/BaseSqliteRepository.cs | 2 +- .../Persistence/SqliteItemRepository.cs | 2 +- .../Persistence/SqliteUserDataRepository.cs | 20 ++++++------- 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/MediaBrowser.Api/Movies/TrailersService.cs b/MediaBrowser.Api/Movies/TrailersService.cs index d74dd5b6ac..c70620cf9f 100644 --- a/MediaBrowser.Api/Movies/TrailersService.cs +++ b/MediaBrowser.Api/Movies/TrailersService.cs @@ -58,7 +58,7 @@ namespace MediaBrowser.Api.Movies getItems.IncludeItemTypes = "Trailer"; - return new ItemsService(_userManager, _libraryManager, _userDataRepository, _localizationManager, _dtoService, _collectionManager) + return new ItemsService(_userManager, _libraryManager, _localizationManager, _dtoService) { AuthorizationContext = AuthorizationContext, Logger = Logger, diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 7721bfd150..795057d673 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -842,17 +842,17 @@ namespace MediaBrowser.Model.Dlna { bool requiresConversion = !StringHelper.EqualsIgnoreCase(subtitleStream.Codec, profile.Format); - if (requiresConversion && !allowConversion) + if (!requiresConversion) { - continue; + return profile; } - if (!requiresConversion) + if (!allowConversion) { - return profile; + continue; } - if (subtitleStream.IsTextSubtitleStream && subtitleStream.SupportsExternalStream) + if (subtitleStream.IsTextSubtitleStream && subtitleStream.SupportsExternalStream && subtitleStream.SupportsSubtitleConversionTo(profile.Format)) { return profile; } diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index af7a034fe0..990de332e1 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -282,6 +282,36 @@ namespace MediaBrowser.Model.Entities !StringHelper.EqualsIgnoreCase(codec, "sub"); } + public bool SupportsSubtitleConversionTo(string codec) + { + if (!IsTextSubtitleStream) + { + return false; + } + + // Can't convert from this + if (StringHelper.EqualsIgnoreCase(Codec, "ass")) + { + return false; + } + if (StringHelper.EqualsIgnoreCase(Codec, "ssa")) + { + return false; + } + + // Can't convert to this + if (StringHelper.EqualsIgnoreCase(codec, "ass")) + { + return false; + } + if (StringHelper.EqualsIgnoreCase(codec, "ssa")) + { + return false; + } + + return true; + } + /// /// Gets or sets a value indicating whether [supports external stream]. /// diff --git a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs index 1bcb02ac39..4f3fe1bf3e 100644 --- a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs @@ -69,14 +69,6 @@ namespace MediaBrowser.Server.Implementations.Library if (stream.IsTextSubtitleStream) { - if (string.Equals(stream.Codec, "ass", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - if (string.Equals(stream.Codec, "ssa", StringComparison.OrdinalIgnoreCase)) - { - return false; - } return true; } diff --git a/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs b/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs index eec5b4b76c..233ab56fed 100644 --- a/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs @@ -8,7 +8,7 @@ namespace MediaBrowser.Server.Implementations.Persistence { public abstract class BaseSqliteRepository : IDisposable { - protected readonly SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1); + protected SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1); protected readonly IDbConnector DbConnector; protected ILogger Logger; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 6d067e345f..d86e52b01c 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -328,7 +328,7 @@ namespace MediaBrowser.Server.Implementations.Persistence new MediaStreamColumns(_connection, Logger).AddColumns(); DataExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb"); - await userDataRepo.Initialize(_connection).ConfigureAwait(false); + await userDataRepo.Initialize(_connection, WriteLock).ConfigureAwait(false); //await Vacuum(_connection).ConfigureAwait(false); } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs index 812e0aa48d..62d9e76347 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs @@ -56,8 +56,10 @@ namespace MediaBrowser.Server.Implementations.Persistence /// Opens the connection to the database /// /// Task. - public async Task Initialize(IDbConnection connection) + public async Task Initialize(IDbConnection connection, SemaphoreSlim writeLock) { + WriteLock.Dispose(); + WriteLock = writeLock; _connection = connection; string[] queries = { @@ -438,18 +440,14 @@ namespace MediaBrowser.Server.Implementations.Persistence return userData; } - protected override void CloseConnection() + protected override void Dispose(bool dispose) { - if (_connection != null) - { - if (_connection.IsOpen()) - { - _connection.Close(); - } + // handled by library database + } - _connection.Dispose(); - _connection = null; - } + protected override void CloseConnection() + { + // handled by library database } } } \ No newline at end of file