MM-15294: migrate commandstore.Update to sync by default (#10745)
* MM-15294: migrate commandstore.Update to sync by default * minor change for code consistency
Этот коммит содержится в:
@@ -502,19 +502,15 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command,
|
|||||||
updatedCmd.CreatorId = oldCmd.CreatorId
|
updatedCmd.CreatorId = oldCmd.CreatorId
|
||||||
updatedCmd.TeamId = oldCmd.TeamId
|
updatedCmd.TeamId = oldCmd.TeamId
|
||||||
|
|
||||||
result := <-a.Srv.Store.Command().Update(updatedCmd)
|
return a.Srv.Store.Command().Update(updatedCmd)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.Command), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError {
|
func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError {
|
||||||
command.TeamId = team.Id
|
command.TeamId = team.Id
|
||||||
|
|
||||||
result := <-a.Srv.Store.Command().Update(command)
|
_, err := a.Srv.Store.Command().Update(command)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return result.Err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -527,12 +523,7 @@ func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppE
|
|||||||
|
|
||||||
cmd.Token = model.NewId()
|
cmd.Token = model.NewId()
|
||||||
|
|
||||||
result := <-a.Srv.Store.Command().Update(cmd)
|
return a.Srv.Store.Command().Update(cmd)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.Data.(*model.Command), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteCommand(commandId string) *model.AppError {
|
func (a *App) DeleteCommand(commandId string) *model.AppError {
|
||||||
|
|||||||
@@ -132,20 +132,18 @@ func (s SqlCommandStore) PermanentDeleteByUser(userId string) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlCommandStore) Update(cmd *model.Command) store.StoreChannel {
|
func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
cmd.UpdateAt = model.GetMillis()
|
||||||
cmd.UpdateAt = model.GetMillis()
|
|
||||||
|
|
||||||
if result.Err = cmd.IsValid(); result.Err != nil {
|
if err := cmd.IsValid(); err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := s.GetMaster().Update(cmd); err != nil {
|
if _, err := s.GetMaster().Update(cmd); err != nil {
|
||||||
result.Err = model.NewAppError("SqlCommandStore.Update", "store.sql_command.save.update.app_error", nil, "id="+cmd.Id+", "+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.save.update.app_error", nil, "id="+cmd.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = cmd
|
|
||||||
}
|
return cmd, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) store.StoreChannel {
|
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) store.StoreChannel {
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ type CommandStore interface {
|
|||||||
Delete(commandId string, time int64) StoreChannel
|
Delete(commandId string, time int64) StoreChannel
|
||||||
PermanentDeleteByTeam(teamId string) StoreChannel
|
PermanentDeleteByTeam(teamId string) StoreChannel
|
||||||
PermanentDeleteByUser(userId string) *model.AppError
|
PermanentDeleteByUser(userId string) *model.AppError
|
||||||
Update(hook *model.Command) StoreChannel
|
Update(hook *model.Command) (*model.Command, *model.AppError)
|
||||||
AnalyticsCommandCount(teamId string) StoreChannel
|
AnalyticsCommandCount(teamId string) StoreChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -218,13 +218,13 @@ func testCommandStoreUpdate(t *testing.T, ss store.Store) {
|
|||||||
|
|
||||||
o1.Token = model.NewId()
|
o1.Token = model.NewId()
|
||||||
|
|
||||||
if r2 := <-ss.Command().Update(o1); r2.Err != nil {
|
if _, err := ss.Command().Update(o1); err != nil {
|
||||||
t.Fatal(r2.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
o1.URL = "junk"
|
o1.URL = "junk"
|
||||||
|
|
||||||
if r2 := <-ss.Command().Update(o1); r2.Err == nil {
|
if _, err := ss.Command().Update(o1); err == nil {
|
||||||
t.Fatal("should have failed - bad URL")
|
t.Fatal("should have failed - bad URL")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,17 +151,26 @@ func (_m *CommandStore) Save(webhook *model.Command) store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update provides a mock function with given fields: hook
|
// Update provides a mock function with given fields: hook
|
||||||
func (_m *CommandStore) Update(hook *model.Command) store.StoreChannel {
|
func (_m *CommandStore) Update(hook *model.Command) (*model.Command, *model.AppError) {
|
||||||
ret := _m.Called(hook)
|
ret := _m.Called(hook)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Command
|
||||||
if rf, ok := ret.Get(0).(func(*model.Command) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(*model.Command) *model.Command); ok {
|
||||||
r0 = rf(hook)
|
r0 = rf(hook)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.Command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(*model.Command) *model.AppError); ok {
|
||||||
|
r1 = rf(hook)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user