diff options
| author | Bond-009 <bond.009@outlook.com> | 2019-04-02 22:15:18 +0200 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2019-06-28 12:14:27 +0200 |
| commit | e88ebd748d98cf9bd2a3978d36254f1644ce751a (patch) | |
| tree | e3316459f42b9c849dd17ebd33d06d646be0b9f3 /Emby.Server.Implementations/Data/BaseSqliteRepository.cs | |
| parent | b6954f3bfd68c87923348444a5923406cf672f9b (diff) | |
Final fixes
Diffstat (limited to 'Emby.Server.Implementations/Data/BaseSqliteRepository.cs')
| -rw-r--r-- | Emby.Server.Implementations/Data/BaseSqliteRepository.cs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index f3bd07bb0..63cef80b0 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using Microsoft.Extensions.Logging; -using SQLitePCL; using SQLitePCL.pretty; namespace Emby.Server.Implementations.Data @@ -23,23 +22,23 @@ namespace Emby.Server.Implementations.Data protected TransactionMode ReadTransactionMode => TransactionMode.Deferred; - protected virtual ConnectionFlags DefaultConnectionFlags => ConnectionFlags.SharedCached | ConnectionFlags.NoMutex; + protected virtual ConnectionFlags DefaultConnectionFlags => ConnectionFlags.NoMutex; - private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1); + protected SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1); - private SQLiteDatabaseConnection _writeConnection; + protected SQLiteDatabaseConnection WriteConnection; private string _defaultWal; protected ManagedConnection GetConnection(bool _ = false) { - _writeLock.Wait(); - if (_writeConnection != null) + WriteLock.Wait(); + if (WriteConnection != null) { - return new ManagedConnection(_writeConnection, _writeLock); + return new ManagedConnection(WriteConnection, WriteLock); } - _writeConnection = SQLite3.Open( + WriteConnection = SQLite3.Open( DbFilePath, DefaultConnectionFlags | ConnectionFlags.Create | ConnectionFlags.ReadWrite, null); @@ -47,38 +46,29 @@ namespace Emby.Server.Implementations.Data if (string.IsNullOrWhiteSpace(_defaultWal)) { - _defaultWal = _writeConnection.Query("PRAGMA journal_mode").SelectScalarString().First(); + _defaultWal = WriteConnection.Query("PRAGMA journal_mode").SelectScalarString().First(); Logger.LogInformation("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal); } if (EnableTempStoreMemory) { - _writeConnection.Execute("PRAGMA temp_store = memory"); + WriteConnection.Execute("PRAGMA temp_store = memory"); } else { - _writeConnection.Execute("PRAGMA temp_store = file"); + WriteConnection.Execute("PRAGMA temp_store = file"); } - return new ManagedConnection(_writeConnection, _writeLock); + return new ManagedConnection(WriteConnection, WriteLock); } public IStatement PrepareStatement(ManagedConnection connection, string sql) => connection.PrepareStatement(sql); - public IStatement PrepareStatementSafe(ManagedConnection connection, string sql) - => connection.PrepareStatement(sql); - public IStatement PrepareStatement(IDatabaseConnection connection, string sql) => connection.PrepareStatement(sql); - public IStatement PrepareStatementSafe(IDatabaseConnection connection, string sql) - => connection.PrepareStatement(sql); - - public IEnumerable<IStatement> PrepareAll(IDatabaseConnection connection, IEnumerable<string> sql) - => PrepareAllSafe(connection, sql); - public IEnumerable<IStatement> PrepareAllSafe(IDatabaseConnection connection, IEnumerable<string> sql) => sql.Select(connection.PrepareStatement); @@ -145,6 +135,7 @@ namespace Emby.Server.Implementations.Data public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } private readonly object _disposeLock = new object(); @@ -162,20 +153,21 @@ namespace Emby.Server.Implementations.Data if (dispose) { - _writeLock.Wait(); + WriteLock.Wait(); try { - _writeConnection.Dispose(); + WriteConnection.Dispose(); } finally { - _writeLock.Release(); + WriteLock.Release(); } - _writeLock.Dispose(); + WriteLock.Dispose(); } - _writeConnection = null; + WriteConnection = null; + WriteLock = null; _disposed = true; } |
