Do not panic when changing tiers, and user is nil

pull/626/head
binwiederhier 2023-02-20 21:46:25 -05:00
parent d92d1ad974
commit 67b45455b8
1 changed files with 6 additions and 2 deletions

View File

@ -330,9 +330,13 @@ func (v *visitor) SetUser(u *user.User) {
v.mu.Lock()
defer v.mu.Unlock()
shouldResetLimiters := v.user.TierID() != u.TierID() // TierID works with nil receiver
v.user = u
v.user = u // u may be nil!
if shouldResetLimiters {
v.resetLimitersNoLock(u.Stats.Messages, u.Stats.Emails, true)
var messages, emails int64
if u != nil {
messages, emails = u.Stats.Messages, u.Stats.Emails
}
v.resetLimitersNoLock(messages, emails, true)
}
}