aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-08-31 21:54:51 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-08-31 21:54:51 -0500
commit11c3f3153c1a37a32546b3f36a07cd4eda1f4268 (patch)
tree0a86c19c115b919cda05df6bf32c742c0c90b9e4 /src
parent64355088fffe7781a0b78e373514d0fdb4053464 (diff)
downloadslskd-11c3f3153c1a37a32546b3f36a07cd4eda1f4268.tar.gz
cache SQLite connections by thread id
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application/SharedFileCache.cs7
1 files changed, 4 insertions, 3 deletions
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<Share> Shares { get; set; }
private SqliteConnection SQLite { get; set; }
private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1);
+ private ConcurrentDictionary<int, SqliteConnection> SQLiteConnections { get; } = new ConcurrentDictionary<int, SqliteConnection>();
/// <summary>
/// Returns the contents of the cache.
@@ -319,11 +321,10 @@ namespace slskd
try
{
- var results = new List<string>();
-
- 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<string>();
sqlite.Open();
var reader = await cmd.ExecuteReaderAsync();