[MM-52973] Avoid thundering herd problem in IsFirstUserAccount (#23549)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9a55280d7a
Коммит
b6b561a8f1
@@ -323,21 +323,31 @@ func (ps *PlatformService) LimitedClientConfig() map[string]string {
|
||||
}
|
||||
|
||||
func (ps *PlatformService) IsFirstUserAccount() bool {
|
||||
if ps.fetchUserCountForFirstUserAccountCheck.Load() {
|
||||
ps.logger.Debug("Fetching user count for first user account check")
|
||||
count, err := ps.Store.User().Count(model.UserCountOptions{IncludeDeleted: true})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
// Avoid calling the user count query in future if we get a count > 0
|
||||
if count > 0 {
|
||||
ps.fetchUserCountForFirstUserAccountCheck.Store(false)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
if !ps.isFirstUserAccount.Load() {
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
ps.isFirstUserAccountLock.Lock()
|
||||
defer ps.isFirstUserAccountLock.Unlock()
|
||||
// Retry under lock as another call might have already succeeded.
|
||||
if !ps.isFirstUserAccount.Load() {
|
||||
return false
|
||||
}
|
||||
|
||||
ps.logger.Debug("Fetching user count for first user account check")
|
||||
count, err := ps.Store.User().Count(model.UserCountOptions{IncludeDeleted: true})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Avoid calling the user count query in future if we get a count > 0
|
||||
if count > 0 {
|
||||
ps.isFirstUserAccount.Store(false)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func (ps *PlatformService) MaxPostSize() int {
|
||||
|
||||
Ссылка в новой задаче
Block a user