From cb7791746327a77410a2f10c762e6fd9297078c1 Mon Sep 17 00:00:00 2001 From: deepsweet Date: Sun, 6 Sep 2026 12:06:49 +0300 Subject: fix favicon.ico relative path in footer In case slskd is hosted not under `/` base URL but rather something like `/slskd`. By default it's trying to fetch `/favicon.ico` which is not there. --- src/web/src/components/AppFooter.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/web/src/components/AppFooter.jsx b/src/web/src/components/AppFooter.jsx index 9a295eb5..31550276 100644 --- a/src/web/src/components/AppFooter.jsx +++ b/src/web/src/components/AppFooter.jsx @@ -69,7 +69,7 @@ const AppFooter = ({ slskd {current && {current}} -- cgit v1.2.3 From 3f70393672447d2bc777c5cfada28f12ddcff22e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 8 Sep 2026 10:16:08 -0500 Subject: use atomic insert/update when activating conversations --- src/slskd/Messaging/ConversationService.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/slskd/Messaging/ConversationService.cs b/src/slskd/Messaging/ConversationService.cs index a744dcca..9873b88b 100644 --- a/src/slskd/Messaging/ConversationService.cs +++ b/src/slskd/Messaging/ConversationService.cs @@ -398,20 +398,23 @@ namespace slskd.Messaging private void ActivateConversation(string username) { - using var context = ContextFactory.CreateDbContext(); + try + { + using var context = ContextFactory.CreateDbContext(); - var conversation = context.Conversations.FirstOrDefault(c => c.Username == username); + context.Database.ExecuteSql($@" + INSERT INTO Conversations (Username, IsActive) + VALUES ({username}, 1) + ON CONFLICT(Username) DO UPDATE SET IsActive = excluded.IsActive; + "); - if (conversation != default) - { - conversation.IsActive = true; + Log.Debug("Successfully activated Conversation for {Username}", username); } - else + catch (Exception ex) { - context.Conversations.Add(new Conversation { Username = username, IsActive = true }); + Log.Warning(ex, "Failed to activate Conversation for {Username}: {Message}", username, ex.Message); + throw; } - - context.SaveChanges(); } } } -- cgit v1.2.3 From bcbb9839144a64df12ecbff26e465129054a5354 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 9 Sep 2026 18:44:51 -0500 Subject: rewrite ./favicon.ico so it's prefixed by urlBase --- src/slskd/Program.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index c998d319..b1f57ce4 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -1067,12 +1067,17 @@ namespace slskd var urlBase = OptionsAtStartup.Web.UrlBase; urlBase = urlBase.StartsWith("/") ? urlBase : "/" + urlBase; - // use urlBase. this effectively just removes urlBase from the path. - // inject urlBase into any html files we serve, and rewrite links to ./static or /static to - // prepend the url base. + // use urlBase. this effectively just removes urlBase from the path before sending it to the next middleware app.UsePathBase(urlBase); + + // rewrite relative html links to ./static or ./favicon.ico to absolute links that include urlBase + // this is necessary because SPA routers (like React Router) mess with the browser's current address app.UseHTMLRewrite("((\\.)?\\/static)", $"{(urlBase == "/" ? string.Empty : urlBase)}/static"); + app.UseHTMLRewrite("((\\.)?\\/favicon\\.ico)", $"{(urlBase == "/" ? string.Empty : urlBase)}/favicon.ico"); + + // inject urlBase and port into any html files we serve as a window-scoped javascript variable app.UseHTMLInjection($"", excludedRoutes: new[] { "/api", "/swagger" }); + Log.Information("Using base url {UrlBase}", urlBase); // serve static content from the configured path -- cgit v1.2.3 From 99cbe43333a70ddf2bfb384b1d7e018343810446 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 9 Sep 2026 18:45:25 -0500 Subject: fix broken favicon link when on a system page --- src/web/src/components/AppFooter.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/web/src/components/AppFooter.jsx b/src/web/src/components/AppFooter.jsx index 31550276..b07af7a2 100644 --- a/src/web/src/components/AppFooter.jsx +++ b/src/web/src/components/AppFooter.jsx @@ -1,3 +1,4 @@ +import { urlBase } from '../config'; import { formatBytes } from '../lib/util'; import React from 'react'; import { Icon, Menu } from 'semantic-ui-react'; @@ -69,7 +70,7 @@ const AppFooter = ({ slskd {current && {current}} -- cgit v1.2.3 From fab938740106725aa8486eb4503cf91cfe8d81e2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 13 Sep 2026 02:20:19 -0500 Subject: add Checkpoint() --- src/slskd/Shares/IShareRepository.cs | 5 +++++ src/slskd/Shares/SqliteShareRepository.cs | 36 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'src') diff --git a/src/slskd/Shares/IShareRepository.cs b/src/slskd/Shares/IShareRepository.cs index 3b57c16f..e9799663 100644 --- a/src/slskd/Shares/IShareRepository.cs +++ b/src/slskd/Shares/IShareRepository.cs @@ -52,6 +52,11 @@ namespace slskd.Shares /// The destination repository. void BackupTo(IShareRepository repository); + /// + /// Checkpoints the current database, flushing the contents of the WAL (write ahead log) into the table(s). + /// + void Checkpoint(); + /// /// Counts the number of directories in the database. /// diff --git a/src/slskd/Shares/SqliteShareRepository.cs b/src/slskd/Shares/SqliteShareRepository.cs index ed594209..a4be81b4 100644 --- a/src/slskd/Shares/SqliteShareRepository.cs +++ b/src/slskd/Shares/SqliteShareRepository.cs @@ -92,6 +92,42 @@ namespace slskd.Shares using var cmd = new SqliteCommand("VACUUM", backupConn); cmd.ExecuteNonQuery(); Log.Debug("Backup vacuumed successfully"); + + /// + /// Checkpoints the current database, flushing the contents of the WAL (write ahead log) into the table(s). + /// + public void Checkpoint() + { + const int maxAttempts = 3; + + using var conn = GetConnection(); + + for (var attempt = 1; attempt <= maxAttempts; attempt++) + { + using var cmd = new SqliteCommand("PRAGMA wal_checkpoint(TRUNCATE);", conn); + using var reader = cmd.ExecuteReader(); + + reader.Read(); + + var busy = reader.GetInt32(0); // another operation prevented the checkpoint (true/false) + var log = reader.GetInt32(1); // number of frames in the WAL at the start + var checkpointed = reader.GetInt32(2); // number of frames moved from the WAL to the db + + if (busy == 0 && checkpointed == log) + { + Log.Debug("WAL checkpoint complete; {Log} frames in log, {Checkpointed} checkpointed", log, checkpointed); + return; + } + + Log.Warning("WAL checkpoint attempt {Attempt} of {MaxAttempts} did not fully complete; {Log} frames in log, {Checkpointed} checkpointed", attempt, maxAttempts, log, checkpointed); + + if (attempt < maxAttempts) + { + System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); + } + } + + throw new TimeoutException($"Failed to fully checkpoint the shares database after {maxAttempts} attempts"); } /// -- cgit v1.2.3 From 6291f9e24cbd54b6c5ad6502101b4d668e51f57f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 13 Sep 2026 02:20:36 -0500 Subject: vacuum and checkpoint after backup --- src/slskd/Shares/SqliteShareRepository.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/SqliteShareRepository.cs b/src/slskd/Shares/SqliteShareRepository.cs index a4be81b4..6d84308a 100644 --- a/src/slskd/Shares/SqliteShareRepository.cs +++ b/src/slskd/Shares/SqliteShareRepository.cs @@ -84,15 +84,23 @@ namespace slskd.Shares /// The destination repository. public void BackupTo(IShareRepository repository) { - using var sourceConn = GetConnection(ConnectionString); - using var backupConn = GetConnection(repository.ConnectionString); - sourceConn.BackupDatabase(backupConn); + using (var sourceConn = GetConnection(ConnectionString)) + using (var backupConn = GetConnection(repository.ConnectionString)) + { + sourceConn.BackupDatabase(backupConn); + } + + using var backupRepository = new SqliteShareRepository(repository.ConnectionString); Log.Debug("Vacuuming backup"); - using var cmd = new SqliteCommand("VACUUM", backupConn); - cmd.ExecuteNonQuery(); + backupRepository.Vacuum(); Log.Debug("Backup vacuumed successfully"); + Log.Debug("Checkpointing backup"); + backupRepository.Checkpoint(); + Log.Debug("Backup checkpointed successfully"); + } + /// /// Checkpoints the current database, flushing the contents of the WAL (write ahead log) into the table(s). /// -- cgit v1.2.3 From 50821750bb392ff06e51d6ef24fe5d9d95af10fc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 13 Sep 2026 02:21:28 -0500 Subject: checkpoint db after vacuum (flush WAL to db) --- src/slskd/Shares/ShareScanner.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs index 7c93d437..c36c0998 100644 --- a/src/slskd/Shares/ShareScanner.cs +++ b/src/slskd/Shares/ShareScanner.cs @@ -358,6 +358,10 @@ namespace slskd.Shares Log.Debug("Vacuuming..."); repository.Vacuum(); Log.Debug("Vacuumed successfully"); + + Log.Debug("Checkpointing..."); + repository.Checkpoint(); + Log.Debug("Checkpointed successfully"); } catch (OperationCanceledException) { -- cgit v1.2.3