From 2e4dd02f76ec9a8487de7e1ceb0b0871c5be766d Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Sat, 22 Jan 2022 21:52:30 +0000 Subject: chore: Add a read only connection for routes like Shows/NextUp --- Emby.Server.Implementations/Data/ManagedConnection.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Emby.Server.Implementations/Data/ManagedConnection.cs') diff --git a/Emby.Server.Implementations/Data/ManagedConnection.cs b/Emby.Server.Implementations/Data/ManagedConnection.cs index 11e33278d..97cb6f26f 100644 --- a/Emby.Server.Implementations/Data/ManagedConnection.cs +++ b/Emby.Server.Implementations/Data/ManagedConnection.cs @@ -9,11 +9,12 @@ namespace Emby.Server.Implementations.Data { public sealed class ManagedConnection : IDisposable { - private readonly SemaphoreSlim _writeLock; + private readonly SemaphoreSlim? _writeLock; private SQLiteDatabaseConnection? _db; - private bool _disposed = false; + private bool _disposed; + public ManagedConnection(SQLiteDatabaseConnection db, SemaphoreSlim writeLock) { @@ -73,7 +74,7 @@ namespace Emby.Server.Implementations.Data return; } - _writeLock.Release(); + _writeLock?.Release(); _db = null; // Don't dispose it _disposed = true; -- cgit v1.2.3 From b705ace262de83867d4d0a04df285d0cc90dd378 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Sat, 5 Mar 2022 12:37:23 -0700 Subject: Apply suggestions from code review --- Emby.Server.Implementations/Data/BaseSqliteRepository.cs | 3 ++- Emby.Server.Implementations/Data/ManagedConnection.cs | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'Emby.Server.Implementations/Data/ManagedConnection.cs') diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index 3387dbec9..b86511482 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -97,6 +97,7 @@ namespace Emby.Server.Implementations.Data /// /// The write connection. protected SQLiteDatabaseConnection WriteConnection { get; set; } + protected SQLiteDatabaseConnection ReadConnection { get; set; } protected ManagedConnection GetConnection(bool readOnly = false) @@ -104,7 +105,7 @@ namespace Emby.Server.Implementations.Data if (readOnly) { ReadConnection ??= SQLite3.Open(DbFilePath, ConnectionFlags.ReadOnly, null); - return new ManagedConnection(ReadConnection, null!); + return new ManagedConnection(ReadConnection, null); } WriteLock.Wait(); diff --git a/Emby.Server.Implementations/Data/ManagedConnection.cs b/Emby.Server.Implementations/Data/ManagedConnection.cs index 97cb6f26f..fe09bdc2a 100644 --- a/Emby.Server.Implementations/Data/ManagedConnection.cs +++ b/Emby.Server.Implementations/Data/ManagedConnection.cs @@ -15,8 +15,7 @@ namespace Emby.Server.Implementations.Data private bool _disposed; - - public ManagedConnection(SQLiteDatabaseConnection db, SemaphoreSlim writeLock) + public ManagedConnection(SQLiteDatabaseConnection db, SemaphoreSlim? writeLock) { _db = db; _writeLock = writeLock; -- cgit v1.2.3