From ec21875fb748bc91b4df85ea62c4813815e25b4a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 22 Feb 2022 21:26:27 -0600 Subject: purge transient users on disconnect --- src/slskd/Users/UserService.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs index 39647e0a..4e252f40 100644 --- a/src/slskd/Users/UserService.cs +++ b/src/slskd/Users/UserService.cs @@ -253,7 +253,21 @@ namespace slskd.Users }; Client.LoggedIn += (_, _) => WatchAllUsers(); - Client.Disconnected += (_, _) => WatchedUsernamesDictionary.Clear(); + Client.Disconnected += (_, _) => + { + // when the client is disconnected, the watched user list resets server-side, + // so clear the watched dictionary to reflect this + WatchedUsernamesDictionary.Clear(); + + // over the course of operation the application will watch users which are not explicitly + // configured as they enqueue uploads. these are considered transiently-tracked users, + // and we want to discard them upon disconnect to avoid re-watching them when the client + // is reconnected. to do this, purge the user dictionary of any entry lacking an explicit group. + foreach (var user in UserDictionary.Values.Where(user => user.Group == null)) + { + UserDictionary.TryRemove(user.Username, out _); + } + }; } private void Configure(Options options) -- cgit v1.2.3