From 9bbedd6f504e33d908fe52815e9b58bcebf7baa4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 21 Sep 2022 20:34:58 -0500 Subject: add Create(). validate tables and create if needed when filling --- src/slskd/Shares/ISharedFileCache.cs | 6 +++++ src/slskd/Shares/SharedFileCache.cs | 50 +++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/slskd/Shares/ISharedFileCache.cs b/src/slskd/Shares/ISharedFileCache.cs index 52c7783c..61312a37 100644 --- a/src/slskd/Shares/ISharedFileCache.cs +++ b/src/slskd/Shares/ISharedFileCache.cs @@ -39,6 +39,12 @@ namespace slskd.Shares /// The contents of the cache. IEnumerable Browse(); + /// + /// (Re)Creates the cache. + /// + /// A value indicating whether an existing cache should be discarded prior to creation. + void Create(bool discardExisting = false); + /// /// Scans the configured shares and fills the cache. /// diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index 4afbfed8..076e1c7a 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -136,6 +136,28 @@ namespace slskd.Shares return directories.Values.OrderBy(d => d.Name); } + /// + /// (Re)Creates the cache. + /// + /// A value indicating whether an existing cache should be discarded prior to creation. + public void Create(bool discardExisting = false) + { + using var conn = GetConnection(); + + if (discardExisting) + { + conn.ExecuteNonQuery("DROP TABLE IF EXISTS directories; DROP TABLE IF EXISTS filenames; DROP TABLE IF EXISTS files;"); + } + + conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS directories (name TEXT PRIMARY KEY, timestamp INTEGER NOT NULL);"); + + conn.ExecuteNonQuery("CREATE VIRTUAL TABLE IF NOT EXISTS filenames USING fts5(maskedFilename);"); + + conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS files " + + "(maskedFilename TEXT PRIMARY KEY, originalFilename TEXT NOT NULL, size BIGINT NOT NULL, touchedAt TEXT NOT NULL, code INTEGER DEFAULT 1 NOT NULL, " + + "extension TEXT, attributeJson TEXT NOT NULL, timestamp INTEGER NOT NULL);"); + } + /// /// Scans the configured shares and fills the cache. /// @@ -153,9 +175,14 @@ namespace slskd.Shares try { - // drop and recreate the tables to clear them - // note: leave the backup in place. this will leave the app in a better position if the app stops during the scan. - CreateTables(); + // it's possible that the database was tampered with between the time it was checked at startup and now + // validate the tables, and if there's an issue, drop and recreate everything. + if (!ValidateTables(Program.ConnectionStrings.Shares)) + { + Log.Warning("Shared file cache invalid; dropping and re-creating prior to scan."); + Create(discardExisting: true); + Log.Information("Share file cache ready."); + } State.SetValue(state => state with { @@ -527,9 +554,9 @@ namespace slskd.Shares { var schema = new Dictionary() { - { "directories", "CREATE TABLE directories (name TEXT PRIMARY KEY)" }, + { "directories", "CREATE TABLE directories (name TEXT PRIMARY KEY, timestamp INTEGER NOT NULL)" }, { "filenames", "CREATE VIRTUAL TABLE filenames USING fts5(maskedFilename)" }, - { "files", "CREATE TABLE files (maskedFilename TEXT PRIMARY KEY, originalFilename TEXT NOT NULL, size BIGINT NOT NULL, touchedAt TEXT NOT NULL, code INTEGER DEFAULT 1 NOT NULL, extension TEXT, attributeJson TEXT NOT NULL)" }, + { "files", "CREATE TABLE files (maskedFilename TEXT PRIMARY KEY, originalFilename TEXT NOT NULL, size BIGINT NOT NULL, touchedAt TEXT NOT NULL, code INTEGER DEFAULT 1 NOT NULL, extension TEXT, attributeJson TEXT NOT NULL, timestamp INTEGER NOT NULL)" }, }; try @@ -601,19 +628,6 @@ namespace slskd.Shares return reader.GetInt32(0); } - private void CreateTables() - { - using var conn = GetConnection(); - - conn.ExecuteNonQuery("DROP TABLE IF EXISTS directories; CREATE TABLE directories (name TEXT PRIMARY KEY);"); - - conn.ExecuteNonQuery("DROP TABLE IF EXISTS filenames; CREATE VIRTUAL TABLE filenames USING fts5(maskedFilename);"); - - conn.ExecuteNonQuery("DROP TABLE IF EXISTS files; CREATE TABLE files " + - "(maskedFilename TEXT PRIMARY KEY, originalFilename TEXT NOT NULL, size BIGINT NOT NULL, touchedAt TEXT NOT NULL, code INTEGER DEFAULT 1 NOT NULL, " + - "extension TEXT, attributeJson TEXT NOT NULL);"); - } - private SqliteConnection GetConnection(string connectionString = null) { var conn = new SqliteConnection(connectionString ?? Program.ConnectionStrings.Shares); -- cgit v1.2.3 From f61ee9c602ba26688db090b0458ab49b768d5170 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 21 Sep 2022 20:35:15 -0500 Subject: add CreateAsync --- src/slskd/Shares/IShareService.cs | 10 ++++++++++ src/slskd/Shares/ShareService.cs | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index 962d4c1e..7ee39313 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -44,6 +44,16 @@ namespace slskd.Shares /// The entire contents of the share. Task> BrowseAsync(); + /// + /// (Re)Creates the cache. + /// + /// + /// This should generally only be called if has returned false. + /// + /// A value indicating whether an existing cache should be discarded prior to creation. + /// The operation context. + Task CreateAsync(bool discardExisting = false); + /// /// Returns the contents of the specified . /// diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 96ac4c1c..d40be652 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -98,6 +98,20 @@ namespace slskd.Shares return Task.FromResult(normalizedResults); } + /// + /// (Re)Creates the cache. + /// + /// + /// This should generally only be called if has returned false. + /// + /// A value indicating whether an existing cache should be discarded prior to creation. + /// The operation context. + public Task CreateAsync(bool discardExisting = false) + { + Cache.Create(discardExisting); + return Task.CompletedTask; + } + /// /// Returns the contents of the specified . /// -- cgit v1.2.3 From 1887d69479c160c5552f040ea3ba2a4765991602 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 21 Sep 2022 20:36:05 -0500 Subject: create cache if it cant be loaded --- src/slskd/Application.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index cab2b649..a64fdf36 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -375,6 +375,11 @@ namespace slskd { Log.Warning("Unable to load share cache from disk. A share scan is required."); + // drop all of the existing tables and recreate them + Log.Information("Recreating share cache..."); + await Shares.CreateAsync(discardExisting: true); + Log.Information("Share cache ready."); + State.SetValue(state => state with { Shares = state.Shares with { ScanPending = true } }); if (OptionsAtStartup.Flags.NoShareScan) -- cgit v1.2.3 From c1a4994fd40cf5909008224ce2ce0457cc6342d6 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 21 Sep 2022 22:54:05 -0500 Subject: remove explicit cache creation --- src/slskd/Application.cs | 9 +++------ src/slskd/Shares/IShareService.cs | 10 ---------- src/slskd/Shares/ISharedFileCache.cs | 6 ------ src/slskd/Shares/ShareService.cs | 14 -------------- 4 files changed, 3 insertions(+), 36 deletions(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a64fdf36..863108c3 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -375,11 +375,6 @@ namespace slskd { Log.Warning("Unable to load share cache from disk. A share scan is required."); - // drop all of the existing tables and recreate them - Log.Information("Recreating share cache..."); - await Shares.CreateAsync(discardExisting: true); - Log.Information("Share cache ready."); - State.SetValue(state => state with { Shares = state.Shares with { ScanPending = true } }); if (OptionsAtStartup.Flags.NoShareScan) @@ -388,6 +383,7 @@ namespace slskd } else { + // todo: should this be forced prior to connection if the cache can't be loaded? _ = Shares.StartScanAsync(); } } @@ -994,7 +990,6 @@ namespace slskd SharesRefreshStarted = DateTime.UtcNow; State.SetValue(s => s with { Shares = current }); - Log.Information("Share scan started"); try { @@ -1005,6 +1000,8 @@ namespace slskd { // noop } + + Log.Information("Share scan started"); } else if (previous.Scanning && !current.Scanning) { diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index 7ee39313..962d4c1e 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -44,16 +44,6 @@ namespace slskd.Shares /// The entire contents of the share. Task> BrowseAsync(); - /// - /// (Re)Creates the cache. - /// - /// - /// This should generally only be called if has returned false. - /// - /// A value indicating whether an existing cache should be discarded prior to creation. - /// The operation context. - Task CreateAsync(bool discardExisting = false); - /// /// Returns the contents of the specified . /// diff --git a/src/slskd/Shares/ISharedFileCache.cs b/src/slskd/Shares/ISharedFileCache.cs index 61312a37..52c7783c 100644 --- a/src/slskd/Shares/ISharedFileCache.cs +++ b/src/slskd/Shares/ISharedFileCache.cs @@ -39,12 +39,6 @@ namespace slskd.Shares /// The contents of the cache. IEnumerable Browse(); - /// - /// (Re)Creates the cache. - /// - /// A value indicating whether an existing cache should be discarded prior to creation. - void Create(bool discardExisting = false); - /// /// Scans the configured shares and fills the cache. /// diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index d40be652..96ac4c1c 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -98,20 +98,6 @@ namespace slskd.Shares return Task.FromResult(normalizedResults); } - /// - /// (Re)Creates the cache. - /// - /// - /// This should generally only be called if has returned false. - /// - /// A value indicating whether an existing cache should be discarded prior to creation. - /// The operation context. - public Task CreateAsync(bool discardExisting = false) - { - Cache.Create(discardExisting); - return Task.CompletedTask; - } - /// /// Returns the contents of the specified . /// -- cgit v1.2.3 From 49552b02365ea7bcb6402296a9baca2e4aec374c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 21 Sep 2022 22:54:34 -0500 Subject: delete stale files at the end of the scan --- src/slskd/Shares/SharedFileCache.cs | 122 +++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 45 deletions(-) diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index 076e1c7a..a3de7e0f 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -136,33 +136,12 @@ namespace slskd.Shares return directories.Values.OrderBy(d => d.Name); } - /// - /// (Re)Creates the cache. - /// - /// A value indicating whether an existing cache should be discarded prior to creation. - public void Create(bool discardExisting = false) - { - using var conn = GetConnection(); - - if (discardExisting) - { - conn.ExecuteNonQuery("DROP TABLE IF EXISTS directories; DROP TABLE IF EXISTS filenames; DROP TABLE IF EXISTS files;"); - } - - conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS directories (name TEXT PRIMARY KEY, timestamp INTEGER NOT NULL);"); - - conn.ExecuteNonQuery("CREATE VIRTUAL TABLE IF NOT EXISTS filenames USING fts5(maskedFilename);"); - - conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS files " + - "(maskedFilename TEXT PRIMARY KEY, originalFilename TEXT NOT NULL, size BIGINT NOT NULL, touchedAt TEXT NOT NULL, code INTEGER DEFAULT 1 NOT NULL, " + - "extension TEXT, attributeJson TEXT NOT NULL, timestamp INTEGER NOT NULL);"); - } - /// /// Scans the configured shares and fills the cache. /// /// The list of shares from which to fill the cache. /// The list of regular expressions used to exclude files or paths from scanning. + /// The optional cancellation token to monitor for cancellation requests. /// The operation context. public async Task FillAsync(IEnumerable shares, IEnumerable filters, CancellationToken cancellationToken = default) { @@ -175,15 +154,6 @@ namespace slskd.Shares try { - // it's possible that the database was tampered with between the time it was checked at startup and now - // validate the tables, and if there's an issue, drop and recreate everything. - if (!ValidateTables(Program.ConnectionStrings.Shares)) - { - Log.Warning("Shared file cache invalid; dropping and re-creating prior to scan."); - Create(discardExisting: true); - Log.Information("Share file cache ready."); - } - State.SetValue(state => state with { Filling = true, @@ -194,10 +164,24 @@ namespace slskd.Shares ExcludedDirectories = 0, }); + // it's possible that the database was tampered with between the time it was checked at startup and now + // validate the tables, and if there's an issue, drop and recreate everything. + if (!ValidateTables(Program.ConnectionStrings.Shares)) + { + Log.Warning("Shared file cache invalid; dropping and re-creating prior to scan."); + CreateTables(discardExisting: true); + Log.Information("Share file cache ready."); + } + Log.Debug("Starting shared file scan"); await Task.Yield(); + // there's an *extremely* unlikely chance that scans run back to back and result in a duplicate scanId + // to be super safe, wait a few milliseconds to make sure that we'll get a new timestamp. + await Task.Delay(50, cancellationToken); + var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + var sw = new Stopwatch(); var swSnapshot = 0L; sw.Start(); @@ -217,7 +201,7 @@ namespace slskd.Shares Shares.Where(s => s.IsExcluded).ToList() .ForEach(s => Log.Information("Excluding {Local}", s.LocalPath)); - Log.Debug("Enumerating shared directories"); + Log.Information("Enumerating shared directories"); swSnapshot = sw.ElapsedMilliseconds; // derive a list of all directories from all shares skip hidden and system directories, as well as anything that @@ -251,10 +235,9 @@ namespace slskd.Shares unmaskedDirectories = unmaskedDirectories.Except(excludedDirectories).ToHashSet(); State.SetValue(state => state with { Directories = unmaskedDirectories.Count, ExcludedDirectories = excludedDirectories.Count() }); - Log.Debug("Found {Directories} shared directories (and {Excluded} were excluded) in {Elapsed}ms. Starting file scan.", unmaskedDirectories.Count, excludedDirectories.Count(), sw.ElapsedMilliseconds - swSnapshot); + Log.Information("Found {Directories} shared directories (and {Excluded} were excluded) in {Elapsed}ms. Starting file scan.", unmaskedDirectories.Count, excludedDirectories.Count(), sw.ElapsedMilliseconds - swSnapshot); swSnapshot = sw.ElapsedMilliseconds; - var maskedDirectories = new HashSet(); var current = 0; var cached = 0; var filtered = 0; @@ -285,8 +268,7 @@ namespace slskd.Shares var share = Shares.First(share => directory.StartsWith(share.LocalPath)); - maskedDirectories.Add(directory.ReplaceFirst(share.LocalPath, share.RemotePath)); - InsertDirectory(directory.ReplaceFirst(share.LocalPath, share.RemotePath)); + InsertDirectory(directory.ReplaceFirst(share.LocalPath, share.RemotePath), timestamp); // recursively find all files in the directory and stick a record in a dictionary, keyed on the sanitized // filename and with a value of a Soulseek.File object @@ -316,7 +298,7 @@ namespace slskd.Shares continue; } - InsertFile(maskedFilename: file.Filename, originalFilename, touchedAt: info.LastWriteTimeUtc, file); + InsertFile(maskedFilename: file.Filename, originalFilename, touchedAt: info.LastWriteTimeUtc, file, timestamp); } } catch (Exception ex) @@ -360,10 +342,13 @@ namespace slskd.Shares await Task.WhenAll(workers.Select(w => w.Completed)); Log.Debug("All workers finished"); - Log.Debug("Directory scan found {Files} files (and {Filtered} were filtered) in {Elapsed}ms", cached, filtered, sw.ElapsedMilliseconds - swSnapshot); + Log.Information("Scan found {Files} files (and {Filtered} were filtered) in {Elapsed}ms", cached, filtered, sw.ElapsedMilliseconds - swSnapshot); swSnapshot = sw.ElapsedMilliseconds; - Log.Debug("Inserted {Files} records in {Elapsed}ms", cached, sw.ElapsedMilliseconds - swSnapshot); + var deletedFiles = DeleteStaleFiles(timestamp); + var deletedDirectories = DeleteStaleDirectories(timestamp); + + Log.Information("Removed or renamed {Files} files and {Directories} directories in {Elapsed}ms", deletedFiles, deletedDirectories, sw.ElapsedMilliseconds - swSnapshot); Log.Debug("Backing up shared file cache database..."); Backup(); @@ -550,6 +535,24 @@ namespace slskd.Shares } } + private void CreateTables(bool discardExisting = false) + { + using var conn = GetConnection(); + + if (discardExisting) + { + conn.ExecuteNonQuery("DROP TABLE IF EXISTS directories; DROP TABLE IF EXISTS filenames; DROP TABLE IF EXISTS files;"); + } + + conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS directories (name TEXT PRIMARY KEY, timestamp INTEGER NOT NULL);"); + + conn.ExecuteNonQuery("CREATE VIRTUAL TABLE IF NOT EXISTS filenames USING fts5(maskedFilename);"); + + conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS files " + + "(maskedFilename TEXT PRIMARY KEY, originalFilename TEXT NOT NULL, size BIGINT NOT NULL, touchedAt TEXT NOT NULL, code INTEGER DEFAULT 1 NOT NULL, " + + "extension TEXT, attributeJson TEXT NOT NULL, timestamp INTEGER NOT NULL);"); + } + private bool ValidateTables(string connectionString) { var schema = new Dictionary() @@ -635,23 +638,38 @@ namespace slskd.Shares return conn; } - private void InsertDirectory(string name) + private void InsertDirectory(string name, long timestamp) { using var conn = GetConnection(); - conn.ExecuteNonQuery("INSERT INTO directories VALUES(@name) ON CONFLICT DO NOTHING;", cmd => + conn.ExecuteNonQuery("INSERT INTO directories VALUES(@name, @timestamp) ON CONFLICT DO UPDATE SET timestamp = excluded.timestamp;", cmd => { cmd.Parameters.AddWithValue("name", name); + cmd.Parameters.AddWithValue("timestamp", timestamp); }); } - private void InsertFile(string maskedFilename, string originalFilename, DateTime touchedAt, File file) + private long DeleteStaleDirectories(long timestamp) { using var conn = GetConnection(); - conn.ExecuteNonQuery("INSERT INTO files (maskedFilename, originalFilename, size, touchedAt, code, extension, attributeJson) " + - "VALUES(@maskedFilename, @originalFilename, @size, @touchedAt, @code, @extension, @attributeJson) " + - "ON CONFLICT DO UPDATE SET originalFilename = excluded.originalFilename, size = excluded.size, touchedAt = excluded.touchedAt, code = excluded.code, extension = excluded.extension, attributeJson = excluded.attributeJson;", cmd => + using var cmd = new SqliteCommand("DELETE FROM directories WHERE timestamp < @timestamp; SELECT changes()", conn); + cmd.Parameters.AddWithValue("timestamp", timestamp); + + var reader = cmd.ExecuteReader(); + reader.Read(); + + return reader.GetInt64(0); + } + + private void InsertFile(string maskedFilename, string originalFilename, DateTime touchedAt, File file, long timestamp) + { + using var conn = GetConnection(); + + conn.ExecuteNonQuery("INSERT INTO files (maskedFilename, originalFilename, size, touchedAt, code, extension, attributeJson, timestamp) " + + "VALUES(@maskedFilename, @originalFilename, @size, @touchedAt, @code, @extension, @attributeJson, @timestamp) " + + "ON CONFLICT DO UPDATE SET originalFilename = excluded.originalFilename, size = excluded.size, touchedAt = excluded.touchedAt, " + + "code = excluded.code, extension = excluded.extension, attributeJson = excluded.attributeJson, timestamp = excluded.timestamp;", cmd => { cmd.Parameters.AddWithValue("maskedFilename", maskedFilename); cmd.Parameters.AddWithValue("originalFilename", originalFilename); @@ -660,6 +678,7 @@ namespace slskd.Shares cmd.Parameters.AddWithValue("code", file.Code); cmd.Parameters.AddWithValue("extension", file.Extension); cmd.Parameters.AddWithValue("attributeJson", file.Attributes.ToJson()); + cmd.Parameters.AddWithValue("timestamp", timestamp); }); conn.ExecuteNonQuery("INSERT INTO filenames (maskedFilename) VALUES(@maskedFilename);", cmd => @@ -668,6 +687,19 @@ namespace slskd.Shares }); } + private long DeleteStaleFiles(long timestamp) + { + using var conn = GetConnection(); + + using var cmd = new SqliteCommand("DELETE FROM files WHERE timestamp < @timestamp; SELECT changes()", conn); + cmd.Parameters.AddWithValue("timestamp", timestamp); + + var reader = cmd.ExecuteReader(); + reader.Read(); + + return reader.GetInt64(0); + } + private IEnumerable ListDirectories() { var results = new List(); -- cgit v1.2.3 From a9853bc7f355dfa5b3cc8d9ca1e7dc3d5b48e17c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Sep 2022 07:44:08 -0500 Subject: remove paranoid wait; it's simply not possible for this to happen concurrently with filesystem changes. --- src/slskd/Shares/SharedFileCache.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index a3de7e0f..a42e8179 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -177,9 +177,6 @@ namespace slskd.Shares await Task.Yield(); - // there's an *extremely* unlikely chance that scans run back to back and result in a duplicate scanId - // to be super safe, wait a few milliseconds to make sure that we'll get a new timestamp. - await Task.Delay(50, cancellationToken); var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); var sw = new Stopwatch(); -- cgit v1.2.3 From e3f8fbd73904262462806e2972799665a3feee57 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Sep 2022 08:39:16 -0500 Subject: remove restrictions on browse, list, and search while scan is in progress --- src/slskd/Shares/SharedFileCache.cs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index a42e8179..6967e44a 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -71,16 +71,6 @@ namespace slskd.Shares /// The contents of the cache. public IEnumerable Browse() { - if (!State.CurrentValue.Filled) - { - if (State.CurrentValue.Filling) - { - return new[] { new Directory("Scanning shares, please check back in a few minutes.") }; - } - - return Enumerable.Empty(); - } - var directories = new ConcurrentDictionary(); // Soulseek requires that each directory in the tree have an entry in the list returned in a browse response. if @@ -382,16 +372,6 @@ namespace slskd.Shares /// The contents of the directory. public Directory List(string directory) { - if (!State.CurrentValue.Filled) - { - if (State.CurrentValue.Filling) - { - return new Directory(directory, new[] { new File(1, "Scanning shares, please check back in a few minutes.", 0, string.Empty) }); - } - - return null; - } - var files = ListFiles(directory); return new Directory(directory, files); } @@ -428,11 +408,6 @@ namespace slskd.Shares /// The matching files. public IEnumerable Search(SearchQuery query) { - if (!State.CurrentValue.Filled) - { - return Enumerable.Empty(); - } - string Clean(string str) => str.Replace("/", " ") .Replace("\\", " ") .Replace(":", " ") -- cgit v1.2.3 From aaf7f5285cad30db7f6eb6743456b38635da5ca0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Sep 2022 08:40:21 -0500 Subject: don't delete browse cache at the start of the scan --- src/slskd/Application.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 863108c3..aa4c5232 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -991,16 +991,6 @@ namespace slskd State.SetValue(s => s with { Shares = current }); - try - { - System.IO.File.Delete(Path.Combine(Program.DataDirectory, "browse.cache")); - Log.Information("Cleared browse response cache"); - } - catch - { - // noop - } - Log.Information("Share scan started"); } else if (previous.Scanning && !current.Scanning) -- cgit v1.2.3 From a860ffdf0a6f016eee88859728db552c42c63233 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Sep 2022 08:47:38 -0500 Subject: fix misplaced using --- src/slskd/Application.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index aa4c5232..20735ead 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -29,8 +29,8 @@ namespace slskd using System.Net.Sockets; using System.Reflection; using System.Runtime; - using System.Text.RegularExpressions; using System.Runtime.InteropServices; + using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; -- cgit v1.2.3