Only force a notifier update if we have to

This commit is contained in:
Neil Alexander 2022-04-26 16:24:09 +01:00
parent 9f155c8f97
commit 8e1b5abd1b
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -87,6 +87,7 @@ func (p *PresenceStreamProvider) populatePresence(
presences map[string]*types.PresenceInternal,
ignoreCache bool,
) error {
var changesMade bool
for _, room := range req.Response.Rooms.Join {
for _, stateEvent := range append(room.State.Events, room.Timeline.Events...) {
switch {
@ -108,13 +109,17 @@ func (p *PresenceStreamProvider) populatePresence(
if err != nil && err != sql.ErrNoRows {
return err
}
changesMade = true
}
}
// TODO: This is expensive, why do we do this?
if err := p.notifier.Load(ctx, p.DB); err != nil {
req.Log.WithError(err).Error("unable to refresh notifier lists")
return err
if changesMade {
// TODO: This is expensive, but seems to be the only thing that
// stops sytest from racing on a couple of remote user tests.
if err := p.notifier.Load(ctx, p.DB); err != nil {
req.Log.WithError(err).Error("unable to refresh notifier lists")
return err
}
}
for _, presence := range presences {