From 688129fbcb2999a055f8d536151871e0d83ced22 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Mon, 2 Oct 2023 16:58:41 +0200 Subject: [PATCH] Tweaks around the device list updater --- userapi/internal/device_list_update.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/userapi/internal/device_list_update.go b/userapi/internal/device_list_update.go index 64b437bf7..a8d347eac 100644 --- a/userapi/internal/device_list_update.go +++ b/userapi/internal/device_list_update.go @@ -180,11 +180,27 @@ func (u *DeviceListUpdater) Start() error { if err != nil { return err } + + // Filter out dupe domains, as processServer is going to get all users anyway + seenDomains := make(map[spec.ServerName]struct{}) + newStateLists := make([]string, 0, len(staleLists)) + for _, userID := range staleLists { + _, domain, err := gomatrixserverlib.SplitID('@', userID) + if err != nil { + // non-fatal and should not block starting up + continue + } + if _, ok := seenDomains[domain]; ok { + continue + } + newStateLists = append(newStateLists, userID) + seenDomains[domain] = struct{}{} + } offset, step := time.Second*10, time.Second - if max := len(staleLists); max > 120 { + if max := len(newStateLists); max > 120 { step = (time.Second * 120) / time.Duration(max) } - for _, userID := range staleLists { + for _, userID := range newStateLists { userID := userID // otherwise we are only sending the last entry time.AfterFunc(offset, func() { u.notifyWorkers(userID) @@ -467,6 +483,11 @@ func (u *DeviceListUpdater) processServer(serverName spec.ServerName) (time.Dura func (u *DeviceListUpdater) processServerUser(ctx context.Context, serverName spec.ServerName, userID string) (time.Duration, error) { ctx, cancel := context.WithTimeout(ctx, requestTimeout) defer cancel() + + // If we are processing more than one user per server, this unblocks further calls to Update + // immediately instead of just after **all** users have been processed. + defer u.clearChannel(userID) + logger := util.GetLogger(ctx).WithFields(logrus.Fields{ "server_name": serverName, "user_id": userID,