From 11c3f3153c1a37a32546b3f36a07cd4eda1f4268 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 31 Aug 2021 21:54:51 -0500 Subject: cache SQLite connections by thread id --- src/slskd/Application/SharedFileCache.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/slskd/Application/SharedFileCache.cs') diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index bcd808ce..d0486efd 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -29,6 +29,7 @@ namespace slskd using System.Threading; using System.Threading.Tasks; using Microsoft.Data.Sqlite; + using Microsoft.Extensions.Caching.Memory; using Serilog; using Soulseek; @@ -59,6 +60,7 @@ namespace slskd private List Shares { get; set; } private SqliteConnection SQLite { get; set; } private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1); + private ConcurrentDictionary SQLiteConnections { get; } = new ConcurrentDictionary(); /// /// Returns the contents of the cache. @@ -319,11 +321,10 @@ namespace slskd try { - var results = new List(); - - using var sqlite = new SqliteConnection("Data Source=file:shares?mode=memory&cache=shared"); + var sqlite = SQLiteConnections.GetOrAdd(Thread.CurrentThread.ManagedThreadId, new SqliteConnection("Data Source=file:shares?mode=memory&cache=shared")); using var cmd = new SqliteCommand(sql, sqlite); + var results = new List(); sqlite.Open(); var reader = await cmd.ExecuteReaderAsync(); -- cgit v1.2.3