Modified updateUserNotifyProps to directly update the field (#18097)

* Modified updateUserNotifyProps to directly update the field

The method was only being used during import and it unnecessarily
made multiple queries to the DB.

Changed to a separate query that just updated the props field.

https://community-daily.mattermost.com/plugins/focalboard/workspace/zyoahc9uapdn3xdptac6jb69ic?id=285b80a3-257d-41f6-8cf4-ed80ca9d92e5&v=495cdb4d-c13a-4992-8eb9-80cfee2819a4&c=e4f9a891-85d6-4886-8590-1e327f7f8b8f

```release-note
NONE
```

* invalidating cache

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2021-08-17 14:21:41 +05:30
коммит произвёл GitHub
родитель d181ae9262
Коммит 132f114793
12 изменённых файлов: 117 добавлений и 34 удалений

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

@@ -1082,7 +1082,6 @@ type AppIface interface {
UpdateUserActive(c *request.Context, userID string, active bool) *model.AppError
UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError)
UpdateUserAuth(userID string, userAuth *model.UserAuth) (*model.UserAuth, *model.AppError)
UpdateUserNotifyProps(userID string, props map[string]string, sendNotifications bool) (*model.User, *model.AppError)
UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
UploadData(c *request.Context, us *model.UploadSession, rd io.Reader) (*model.FileInfo, *model.AppError)

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

@@ -527,7 +527,10 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
}
}
if hasNotifyPropsChanged {
if savedUser, appErr = a.UpdateUserNotifyProps(user.Id, user.NotifyProps, false); appErr != nil {
if appErr = a.updateUserNotifyProps(user.Id, user.NotifyProps); appErr != nil {
return appErr
}
if savedUser, appErr = a.GetUser(user.Id); appErr != nil {
return appErr
}
}

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

@@ -16816,28 +16816,6 @@ func (a *OpenTracingAppLayer) UpdateUserAuth(userID string, userAuth *model.User
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) UpdateUserNotifyProps(userID string, props map[string]string, sendNotifications bool) (*model.User, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserNotifyProps")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.UpdateUserNotifyProps(userID, props, sendNotifications)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserRoles")

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

@@ -1143,20 +1143,22 @@ func (a *App) UpdateUserActive(c *request.Context, userID string, active bool) *
return nil
}
func (a *App) UpdateUserNotifyProps(userID string, props map[string]string, sendNotifications bool) (*model.User, *model.AppError) {
user, err := a.GetUser(userID)
func (a *App) updateUserNotifyProps(userID string, props map[string]string) *model.AppError {
err := a.srv.userService.UpdateUserNotifyProps(userID, props)
if err != nil {
return nil, err
var appErr *model.AppError
switch {
case errors.As(err, &appErr):
return appErr
default:
return model.NewAppError("UpdateUser", "app.user.update.finding.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
user.NotifyProps = props
a.InvalidateCacheForUser(userID)
a.onUserProfileChange(userID)
ruser, err := a.UpdateUser(user, sendNotifications)
if err != nil {
return nil, err
}
return ruser, nil
return nil
}
func (a *App) UpdateMfa(activate bool, userID, token string) *model.AppError {