aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Application/Shares
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-08-02 08:13:48 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-08-02 08:13:48 -0500
commita2ce1945f76f4a6f54483436cae7d3539a91be38 (patch)
tree32d33a2aa61e1b3214e395c86e8e3e76b21fdebc /src/slskd/Application/Shares
parentad8b3dabef05aa9c7edba5fbb22e071baa3e95e1 (diff)
downloadslskd-a2ce1945f76f4a6f54483436cae7d3539a91be38.tar.gz
rename stuff
Diffstat (limited to 'src/slskd/Application/Shares')
-rw-r--r--src/slskd/Application/Shares/ISharedFileCache.cs (renamed from src/slskd/Application/Shares/ISharesService.cs)20
-rw-r--r--src/slskd/Application/Shares/SharedFileCache.cs (renamed from src/slskd/Application/Shares/SharesService.cs)35
-rw-r--r--src/slskd/Application/Shares/SharedFileCacheState.cs (renamed from src/slskd/Application/Shares/SharesState.cs)26
3 files changed, 59 insertions, 22 deletions
diff --git a/src/slskd/Application/Shares/ISharesService.cs b/src/slskd/Application/Shares/ISharedFileCache.cs
index 78fe3e12..22667a7a 100644
--- a/src/slskd/Application/Shares/ISharesService.cs
+++ b/src/slskd/Application/Shares/ISharedFileCache.cs
@@ -1,4 +1,4 @@
-// <copyright file="ISharesService.cs" company="slskd Team">
+// <copyright file="ISharedFileCache.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -21,12 +21,28 @@ namespace slskd.Shares
using System.Threading.Tasks;
using Soulseek;
- public interface ISharesService
+ /// <summary>
+ /// Shared file cache.
+ /// </summary>
+ public interface ISharedFileCache
{
+ /// <summary>
+ /// Returns the contents of the cache.
+ /// </summary>
+ /// <returns>The contents of the cache.</returns>
IEnumerable<Directory> Browse();
+ /// <summary>
+ /// Drops and re-creates the cache from disk.
+ /// </summary>
+ /// <returns>The operation context.</returns>
Task FillAsync();
+ /// <summary>
+ /// Searches the cache for the specified <paramref name="query"/> and returns the matching files.
+ /// </summary>
+ /// <param name="query">The query for which to search.</param>
+ /// <returns>The matching files.</returns>
Task<IEnumerable<File>> SearchAsync(SearchQuery query);
}
} \ No newline at end of file
diff --git a/src/slskd/Application/Shares/SharesService.cs b/src/slskd/Application/Shares/SharedFileCache.cs
index f5fbb88d..efc43a17 100644
--- a/src/slskd/Application/Shares/SharesService.cs
+++ b/src/slskd/Application/Shares/SharedFileCache.cs
@@ -1,4 +1,4 @@
-// <copyright file="SharesService.cs" company="slskd Team">
+// <copyright file="SharedFileCache.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -31,38 +31,37 @@ namespace slskd.Shares
using Soulseek;
/// <summary>
- /// Caches shared files.
+ /// Shared file cache.
/// </summary>
- public class SharesService : ISharesService
+ public class SharedFileCache : ISharedFileCache
{
/// <summary>
- /// Initializes a new instance of the <see cref="SharesService"/> class.
+ /// Initializes a new instance of the <see cref="SharedFileCache"/> class.
/// </summary>
/// <param name="stateMonitor"></param>
/// <param name="optionsMonitor"></param>
- public SharesService(
- IStateMonitor<SharesState> stateMonitor,
+ public SharedFileCache(
+ IStateMonitor<SharedFileCacheState> stateMonitor,
IOptionsMonitor<Options> optionsMonitor)
{
StateMonitor = stateMonitor;
OptionsMonitor = optionsMonitor;
-
- State = new SharesState() { Ready = false, FillProgress = 0 };
}
- public IEnumerable<string> Shares => OptionsMonitor.CurrentValue.Directories.Shared;
- public SharesState State { get; }
-
private HashSet<string> Directories { get; set; }
private Dictionary<string, Soulseek.File> Files { get; set; }
private IOptionsMonitor<Options> OptionsMonitor { get; set; }
private SqliteConnection SQLite { get; set; }
- private IStateMonitor<SharesState> StateMonitor { get; set; }
+ private IStateMonitor<SharedFileCacheState> StateMonitor { get; set; }
private ReaderWriterLockSlim SyncRoot { get; } = new ReaderWriterLockSlim();
+ /// <summary>
+ /// Returns the contents of the cache.
+ /// </summary>
+ /// <returns>The contents of the cache.</returns>
public IEnumerable<Soulseek.Directory> Browse()
{
- if (!State.Ready)
+ if (!StateMonitor.CurrentValue.Ready)
{
return Enumerable.Empty<Soulseek.Directory>();
}
@@ -117,11 +116,11 @@ namespace slskd.Shares
try
{
- StateMonitor.Set(state => state with { Ready = false, FillProgress = 0 });
+ StateMonitor.SetValue(state => state with { Ready = false, FillProgress = 0 });
CreateTable();
- var directories = Shares
+ var directories = OptionsMonitor.CurrentValue.Directories.Shared
.SelectMany(share => System.IO.Directory.GetDirectories(share, "*", SearchOption.AllDirectories))
.ToHashSet();
@@ -150,7 +149,7 @@ namespace slskd.Shares
}
current++;
- StateMonitor.Set(state => state with { Ready = false, FillProgress = current / (double)total, Directories = current, Files = files.Count });
+ StateMonitor.SetValue(state => state with { Ready = false, FillProgress = current / (double)total, Directories = current, Files = files.Count });
}
// potentially optimize with multi-valued insert https://stackoverflow.com/questions/16055566/insert-multiple-rows-in-sqlite
@@ -162,7 +161,7 @@ namespace slskd.Shares
Directories = directories;
Files = files;
- StateMonitor.Set(state => state with { Ready = true, FillProgress = 1, Directories = directories.Count, Files = files.Count });
+ StateMonitor.SetValue(state => state with { Ready = true, FillProgress = 1, Directories = directories.Count, Files = files.Count });
}
finally
{
@@ -179,7 +178,7 @@ namespace slskd.Shares
/// <returns></returns>
public async Task<IEnumerable<Soulseek.File>> SearchAsync(SearchQuery query)
{
- if (!State.Ready)
+ if (!StateMonitor.CurrentValue.Ready)
{
return Enumerable.Empty<Soulseek.File>();
}
diff --git a/src/slskd/Application/Shares/SharesState.cs b/src/slskd/Application/Shares/SharedFileCacheState.cs
index bea4b308..4bda9d7b 100644
--- a/src/slskd/Application/Shares/SharesState.cs
+++ b/src/slskd/Application/Shares/SharedFileCacheState.cs
@@ -1,4 +1,4 @@
-// <copyright file="SharesState.cs" company="slskd Team">
+// <copyright file="SharedFileCacheState.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -17,14 +17,36 @@
namespace slskd.Shares
{
+ using System;
+
/// <summary>
/// Share cache state.
/// </summary>
- public record SharesState()
+ public record SharedFileCacheState()
{
+ /// <summary>
+ /// Gets a value indicating whether the cache is ready to be used.
+ /// </summary>
public bool Ready { get; init; } = true;
+
+ /// <summary>
+ /// Gets the current fill progress.
+ /// </summary>
public double FillProgress { get; init; } = 1;
+
+ /// <summary>
+ /// Gets the number of cached directories.
+ /// </summary>
public int Directories { get; init; }
+
+ /// <summary>
+ /// Gets the number of cached files.
+ /// </summary>
public int Files { get; init; }
+
+ /// <summary>
+ /// Gets the UTC timestamp of the last fill.
+ /// </summary>
+ public DateTime? LastFilled { get; init; }
}
}