Avoid calling the user count query in future if we get a count > 0 (#23545)

* Avoid calling the user count query in future if we get a count > 0

* re-adding mock session to avoid adding the old mitigation in future

* adjustments based on feedback
Этот коммит содержится в:
Ben Cooke
2023-05-30 21:34:01 -04:00
коммит произвёл GitHub
родитель 14fcc8a22e
Коммит 427635a96f
3 изменённых файлов: 36 добавлений и 28 удалений

Просмотреть файл

@@ -326,12 +326,20 @@ func (ps *PlatformService) LimitedClientConfig() map[string]string {
}
func (ps *PlatformService) IsFirstUserAccount() bool {
count, err := ps.Store.User().Count(model.UserCountOptions{IncludeDeleted: true})
if err != nil {
return false
if ps.fetchUserCountForFirstUserAccountCheck.Load() {
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
}
return count <= 0
return false
}
func (ps *PlatformService) MaxPostSize() int {