소스 검색

Merge pull request #7240 from jaysonsantos/add-readonly-connection

Cody Robibero 3 년 전
부모
커밋
bc3cb04c0b
2개의 변경된 파일12개의 추가작업 그리고 4개의 파일을 삭제
  1. 8 0
      Emby.Server.Implementations/Data/BaseSqliteRepository.cs
  2. 4 4
      Emby.Server.Implementations/Data/ManagedConnection.cs

+ 8 - 0
Emby.Server.Implementations/Data/BaseSqliteRepository.cs

@@ -98,8 +98,16 @@ namespace Emby.Server.Implementations.Data
         /// <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, ConnectionFlags.ReadOnly, null);
+                return new ManagedConnection(ReadConnection, null);
+            }
+
             WriteLock.Wait();
             if (WriteConnection != null)
             {

+ 4 - 4
Emby.Server.Implementations/Data/ManagedConnection.cs

@@ -9,13 +9,13 @@ 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)
+        public ManagedConnection(SQLiteDatabaseConnection db, SemaphoreSlim? writeLock)
         {
             _db = db;
             _writeLock = writeLock;
@@ -73,7 +73,7 @@ namespace Emby.Server.Implementations.Data
                 return;
             }
 
-            _writeLock.Release();
+            _writeLock?.Release();
 
             _db = null; // Don't dispose it
             _disposed = true;