MM-15294: migrate commandstore.Update to sync by default (#10745)

* MM-15294: migrate commandstore.Update to sync by default

* minor change for code consistency
This commit is contained in:
Puneeth Reddy
2019-04-29 07:22:44 -07:00
committed by Lev
parent dec3c8facb
commit 5b70962f71
5 changed files with 33 additions and 35 deletions

View File

@@ -502,19 +502,15 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command,
updatedCmd.CreatorId = oldCmd.CreatorId
updatedCmd.TeamId = oldCmd.TeamId
result := <-a.Srv.Store.Command().Update(updatedCmd)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Command), nil
return a.Srv.Store.Command().Update(updatedCmd)
}
func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError {
command.TeamId = team.Id
result := <-a.Srv.Store.Command().Update(command)
if result.Err != nil {
return result.Err
_, err := a.Srv.Store.Command().Update(command)
if err != nil {
return err
}
return nil
@@ -527,12 +523,7 @@ func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppE
cmd.Token = model.NewId()
result := <-a.Srv.Store.Command().Update(cmd)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Command), nil
return a.Srv.Store.Command().Update(cmd)
}
func (a *App) DeleteCommand(commandId string) *model.AppError {

View File

@@ -132,20 +132,18 @@ func (s SqlCommandStore) PermanentDeleteByUser(userId string) *model.AppError {
return nil
}
func (s SqlCommandStore) Update(cmd *model.Command) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
cmd.UpdateAt = model.GetMillis()
func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppError) {
cmd.UpdateAt = model.GetMillis()
if result.Err = cmd.IsValid(); result.Err != nil {
return
}
if err := cmd.IsValid(); err != nil {
return nil, err
}
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)
} else {
result.Data = cmd
}
})
if _, err := s.GetMaster().Update(cmd); err != nil {
return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.save.update.app_error", nil, "id="+cmd.Id+", "+err.Error(), http.StatusInternalServerError)
}
return cmd, nil
}
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) store.StoreChannel {

View File

@@ -411,7 +411,7 @@ type CommandStore interface {
Delete(commandId string, time int64) StoreChannel
PermanentDeleteByTeam(teamId string) StoreChannel
PermanentDeleteByUser(userId string) *model.AppError
Update(hook *model.Command) StoreChannel
Update(hook *model.Command) (*model.Command, *model.AppError)
AnalyticsCommandCount(teamId string) StoreChannel
}

View File

@@ -218,13 +218,13 @@ func testCommandStoreUpdate(t *testing.T, ss store.Store) {
o1.Token = model.NewId()
if r2 := <-ss.Command().Update(o1); r2.Err != nil {
t.Fatal(r2.Err)
if _, err := ss.Command().Update(o1); err != nil {
t.Fatal(err)
}
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")
}
}

View File

@@ -151,17 +151,26 @@ func (_m *CommandStore) Save(webhook *model.Command) store.StoreChannel {
}
// 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)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(*model.Command) store.StoreChannel); ok {
var r0 *model.Command
if rf, ok := ret.Get(0).(func(*model.Command) *model.Command); ok {
r0 = rf(hook)
} else {
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
}