The Free Software Media System - Server Backend & API
chore: Add a read only connection for routes like Shows/NextUp
Jayson Reis2e4dd02f76ec
diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.csindex 450688491a..3ca9977c85 100644--- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs+++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs@@ -97,9 +97,16 @@ namespace Emby.Server.Implementations.Data/// </summary>/// <value>The write connection.</value>protected SQLiteDatabaseConnection WriteConnection { get; set; }+ protected SQLiteDatabaseConnection ReadConnection { get; set; }protected ManagedConnection GetConnection(bool readOnly = false){+ if (readOnly)+ {+ ReadConnection ??= SQLite3.Open(DbFilePath, DefaultConnectionFlags | ConnectionFlags.ReadOnly, null);+ return new ManagedConnection(ReadConnection, null);+ }+WriteLock.Wait();if (WriteConnection != null){diff --git a/Emby.Server.Implementations/Data/ManagedConnection.cs b/Emby.Server.Implementations/Data/ManagedConnection.csindex 11e33278d4..97cb6f26f8 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.Datareturn;}- _writeLock.Release();+ _writeLock?.Release();_db = null; // Don't dispose it_disposed = true;