Cleanup unnecessary concurrent db calls on user (#16912)
Этот коммит содержится в:
26
app/user.go
26
app/user.go
@@ -352,19 +352,6 @@ func (a *App) CreateOAuthUser(service string, userData io.Reader, teamID string,
|
|||||||
user.AuthService = service
|
user.AuthService = service
|
||||||
}
|
}
|
||||||
|
|
||||||
suchan := make(chan store.StoreResult, 1)
|
|
||||||
euchan := make(chan store.StoreResult, 1)
|
|
||||||
go func() {
|
|
||||||
userByAuth, err := a.Srv().Store.User().GetByAuth(user.AuthData, service)
|
|
||||||
suchan <- store.StoreResult{Data: userByAuth, NErr: err}
|
|
||||||
close(suchan)
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
userByEmail, err := a.Srv().Store.User().GetByEmail(user.Email)
|
|
||||||
euchan <- store.StoreResult{Data: userByEmail, NErr: err}
|
|
||||||
close(euchan)
|
|
||||||
}()
|
|
||||||
|
|
||||||
found := true
|
found := true
|
||||||
count := 0
|
count := 0
|
||||||
for found {
|
for found {
|
||||||
@@ -374,16 +361,17 @@ func (a *App) CreateOAuthUser(service string, userData io.Reader, teamID string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-suchan; result.NErr == nil {
|
userByAuth, _ := a.Srv().Store.User().GetByAuth(user.AuthData, service)
|
||||||
return result.Data.(*model.User), nil
|
if userByAuth != nil {
|
||||||
|
return userByAuth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-euchan; result.NErr == nil {
|
userByEmail, _ := a.Srv().Store.User().GetByEmail(user.Email)
|
||||||
authService := result.Data.(*model.User).AuthService
|
if userByEmail != nil {
|
||||||
if authService == "" {
|
if userByEmail.AuthService == "" {
|
||||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.already_attached.app_error", map[string]interface{}{"Service": service, "Auth": model.USER_AUTH_SERVICE_EMAIL}, "email="+user.Email, http.StatusBadRequest)
|
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.already_attached.app_error", map[string]interface{}{"Service": service, "Auth": model.USER_AUTH_SERVICE_EMAIL}, "email="+user.Email, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.already_attached.app_error", map[string]interface{}{"Service": service, "Auth": authService}, "email="+user.Email, http.StatusBadRequest)
|
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.already_attached.app_error", map[string]interface{}{"Service": service, "Auth": userByEmail.AuthService}, "email="+user.Email, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
user.EmailVerified = true
|
user.EmailVerified = true
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user