diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-02-01 21:43:36 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-02-01 21:43:36 -0600 |
| commit | a2206e6b06980e270dd57e8255c61612c4f52ca7 (patch) | |
| tree | db14a426c7ee54831ed6113d66456832481e1184 /src | |
| parent | a7d5a64092cd76b632aeac9d8476d912c96adf5b (diff) | |
| download | slskd-a2206e6b06980e270dd57e8255c61612c4f52ca7.tar.gz | |
sort groups by priority when mapping users
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Users/UserService.cs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs index 1f037d3d..5a6170fc 100644 --- a/src/slskd/Users/UserService.cs +++ b/src/slskd/Users/UserService.cs @@ -20,7 +20,9 @@ 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; @@ -60,17 +62,21 @@ namespace slskd.Users private IDbContextFactory<UserDbContext> ContextFactory { get; } private IOptionsMonitor<Options> OptionsMonitor { get; } private ILogger Log { get; set; } = Serilog.Log.ForContext<UserService>(); - private Dictionary<string, string> Map { get; set; } = new Dictionary<string, string>(); + private ConcurrentDictionary<string, string> Map { get; set; } = new ConcurrentDictionary<string, string>(); private void Configure(Options options) { - var map = new Dictionary<string, string>(); + var map = new ConcurrentDictionary<string, string>(); - foreach (var group in options.Groups.UserDefined) + // sort by priority, ascending + foreach (var group in options.Groups.UserDefined.OrderBy(kvp => kvp.Value.Upload.Priority)) { foreach (var user in group.Value.Members) { - map.Add(user, group.Key); + // if the key already exists, leave the existing entry. + // if a user appears in more than one group, the higher priority (lower numbered) + // group is their effective group. + map.TryAdd(user, group.Key); } } |
