diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-09-07 21:39:25 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-09-07 21:39:25 -0500 |
| commit | dcee8c07f9a76e4299b59e81e80a07f6df126ee3 (patch) | |
| tree | 3d3950ade5a3bc497e4a09ad25f328c3bfe1ba11 /src/slskd/Application.cs | |
| parent | e3a189f3bf17a868e65b61754378f0af0db4fd46 (diff) | |
| download | slskd-dcee8c07f9a76e4299b59e81e80a07f6df126ee3.tar.gz | |
wip
Diffstat (limited to 'src/slskd/Application.cs')
| -rw-r--r-- | src/slskd/Application.cs | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index e4d47bb1..6c6ee475 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -369,14 +369,22 @@ namespace slskd _ = CheckVersionAsync(); } - if (OptionsAtStartup.Flags.NoShareScan) - { - Log.Warning("Not scanning shares; 'no-share-scan' option is enabled. Search and browse results will remain disabled until a manual scan is completed."); - } - else - { - _ = Shares.StartScanAsync(); - } + //if (OptionsAtStartup.Flags.NoShareScan) + //{ + // Log.Warning("Not scanning shares; 'no-share-scan' option is enabled. Search and browse results will remain disabled until a manual scan is completed."); + //} + //else + //{ + // _ = Shares.StartScanAsync(); + //} + + Shares.LoadFromDisk(); + Log.Information("Shares loaded from disk"); + + Log.Information("Caching browse response..."); + var browse = new BrowseResponse(await Shares.BrowseAsync()).ToByteArray(); + System.IO.File.WriteAllBytes(Path.Combine(Program.DataDirectory, "browse.cache"), browse); + Log.Information("Browse response cached."); if (OptionsAtStartup.Flags.NoConnect) { @@ -417,7 +425,21 @@ namespace slskd var sw = new Stopwatch(); sw.Start(); - var directories = await Shares.BrowseAsync(); + BrowseResponse response = default; + + var cacheFilename = Path.Combine(Program.DataDirectory, "browse.cache"); + var cacheFileInfo = new System.IO.FileInfo(cacheFilename); + + if (cacheFileInfo.Exists) + { + var stream = new System.IO.FileStream(cacheFilename, FileMode.Open, FileAccess.Read); + response = new RawBrowseResponse(cacheFileInfo.Length, stream); + } + else + { + var directories = await Shares.BrowseAsync(); + response = new BrowseResponse(directories); + } sw.Stop(); @@ -425,7 +447,7 @@ namespace slskd Metrics.Browse.CurrentResponseLatency.Update(sw.ElapsedMilliseconds); Metrics.Browse.ResponsesSent.Inc(1); - return new BrowseResponse(directories); + return response; } catch (Exception ex) { |
