diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-03-23 10:16:58 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-03-23 10:16:58 -0500 |
| commit | cff862e12a846c6328d5cf77e2b12187cc6d4e30 (patch) | |
| tree | fd3bf6ccae6f7e086944d7d28494c78d6ca75f3c | |
| parent | 2b64f48bc6acb79bd2844333afea7e7a70d77a22 (diff) | |
| download | slskd-cff862e12a846c6328d5cf77e2b12187cc6d4e30.tar.gz | |
don't save user info to a database
| -rw-r--r-- | src/slskd/Users/IUserService.cs | 5 | ||||
| -rw-r--r-- | src/slskd/Users/UserService.cs | 39 |
2 files changed, 5 insertions, 39 deletions
diff --git a/src/slskd/Users/IUserService.cs b/src/slskd/Users/IUserService.cs index e78b1b1c..88090f9f 100644 --- a/src/slskd/Users/IUserService.cs +++ b/src/slskd/Users/IUserService.cs @@ -47,9 +47,8 @@ namespace slskd.Users /// Retrieves peer <see cref="Info"/>. /// </summary> /// <param name="username">The username of the peer.</param> - /// <param name="bypassCache">A value indicating whether the local cache should be bypassed.</param> - /// <returns>The cached or retrieved info.</returns> - Task<Info> GetInfoAsync(string username, bool bypassCache = false); + /// <returns>The retrieved info.</returns> + Task<Info> GetInfoAsync(string username); /// <summary> /// Retrieves a peer's IP endpoint, including their IP address and listen port. diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs index f081d8b1..aa2ae234 100644 --- a/src/slskd/Users/UserService.cs +++ b/src/slskd/Users/UserService.cs @@ -19,13 +19,11 @@ using Microsoft.Extensions.Options; namespace slskd.Users { - using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; - using Microsoft.EntityFrameworkCore; using Serilog; using Soulseek; @@ -34,27 +32,21 @@ namespace slskd.Users /// </summary> public class UserService : IUserService { - private const int CacheTTLSeconds = 300; - /// <summary> /// Initializes a new instance of the <see cref="UserService"/> class. /// </summary> /// <param name="soulseekClient"></param> /// <param name="stateMutator"></param> - /// <param name="contextFactory">The database context to use.</param> /// <param name="optionsMonitor"></param> public UserService( ISoulseekClient soulseekClient, IStateMutator<State> stateMutator, - IDbContextFactory<UserDbContext> contextFactory, IOptionsMonitor<Options> optionsMonitor) { Client = soulseekClient; StateMutator = stateMutator; - ContextFactory = contextFactory; - OptionsMonitor = optionsMonitor; OptionsMonitor.OnChange(options => Configure(options)); @@ -87,7 +79,6 @@ namespace slskd.Users public IReadOnlyList<string> WatchedUsernames => WatchedUsernamesDictionary.Keys.ToList().AsReadOnly(); private ISoulseekClient Client { get; } - private IDbContextFactory<UserDbContext> ContextFactory { get; } private string LastOptionsHash { get; set; } private ILogger Log { get; set; } = Serilog.Log.ForContext<UserService>(); private IOptionsMonitor<Options> OptionsMonitor { get; } @@ -130,35 +121,11 @@ namespace slskd.Users /// Retrieves peer <see cref="Info"/>. /// </summary> /// <param name="username">The username of the peer.</param> - /// <param name="bypassCache">A value indicating whether the local cache should be bypassed.</param> - /// <returns>The cached or retrieved info.</returns> - public async Task<Info> GetInfoAsync(string username, bool bypassCache = false) + /// <returns>The retrieved info.</returns> + public async Task<Info> GetInfoAsync(string username) { - using var context = ContextFactory.CreateDbContext(); - - var info = await context.Info.AsNoTracking().FirstOrDefaultAsync(peer => peer.Username == username); - var peerExists = info != default; - - if (!bypassCache && peerExists && info.UpdatedAt < DateTime.UtcNow.AddSeconds(CacheTTLSeconds)) - { - return info; - } - var soulseekUserInfo = await Client.GetUserInfoAsync(username); - info = Info.FromSoulseekUserInfo(username, soulseekUserInfo); - - if (peerExists) - { - context.Update(info); - } - else - { - context.Add(info); - } - - await context.SaveChangesAsync(); - - return info; + return soulseekUserInfo.ToInfo(); } /// <summary> |
