MM-15288: Migrate CommandStore.Get to sync by default (#10739)
* MM-15288: Migrate Command.Get to sync by default * addressing review comments, updating status code of err returned by Get Method
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
fc15eda37f
Коммит
2d3fb4f426
@@ -474,13 +474,13 @@ func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
|
|||||||
return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := <-a.Srv.Store.Command().Get(commandId)
|
cmd, err := a.Srv.Store.Command().Get(commandId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
result.Err.StatusCode = http.StatusNotFound
|
err.StatusCode = http.StatusNotFound
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.Data.(*model.Command), nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError) {
|
func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError) {
|
||||||
|
|||||||
@@ -686,11 +686,9 @@ func (a *App) HandleCommandWebhook(hookId string, response *model.CommandRespons
|
|||||||
hook = result.Data.(*model.CommandWebhook)
|
hook = result.Data.(*model.CommandWebhook)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd *model.Command
|
cmd, err := a.Srv.Store.Command().Get(hook.CommandId)
|
||||||
if result := <-a.Srv.Store.Command().Get(hook.CommandId); result.Err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "err="+result.Err.Message, http.StatusBadRequest)
|
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "err="+err.Message, http.StatusBadRequest)
|
||||||
} else {
|
|
||||||
cmd = result.Data.(*model.Command)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args := &model.CommandArgs{
|
args := &model.CommandArgs{
|
||||||
@@ -705,6 +703,6 @@ func (a *App) HandleCommandWebhook(hookId string, response *model.CommandRespons
|
|||||||
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.invalid.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode)
|
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.invalid.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := a.HandleCommandResponse(cmd, args, response, false)
|
_, err = a.HandleCommandResponse(cmd, args, response, false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,7 @@ func getCommandFromCommandArg(a *app.App, commandArg string) *model.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if command == nil {
|
if command == nil {
|
||||||
if result := <-a.Srv.Store.Command().Get(commandPart); result.Err == nil {
|
command, _ = a.Srv.Store.Command().Get(commandPart)
|
||||||
command = result.Data.(*model.Command)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return command
|
return command
|
||||||
|
|||||||
@@ -61,16 +61,14 @@ func (s SqlCommandStore) Save(command *model.Command) (*model.Command, *model.Ap
|
|||||||
return command, nil
|
return command, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlCommandStore) Get(id string) store.StoreChannel {
|
func (s SqlCommandStore) Get(id string) (*model.Command, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var command model.Command
|
||||||
var command model.Command
|
|
||||||
|
|
||||||
if err := s.GetReplica().SelectOne(&command, "SELECT * FROM Commands WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id}); err != nil {
|
if err := s.GetReplica().SelectOne(&command, "SELECT * FROM Commands WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlCommandStore.Get", "store.sql_command.save.get.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlCommandStore.Get", "store.sql_command.save.get.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = &command
|
return &command, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ type WebhookStore interface {
|
|||||||
|
|
||||||
type CommandStore interface {
|
type CommandStore interface {
|
||||||
Save(webhook *model.Command) (*model.Command, *model.AppError)
|
Save(webhook *model.Command) (*model.Command, *model.AppError)
|
||||||
Get(id string) StoreChannel
|
Get(id string) (*model.Command, *model.AppError)
|
||||||
GetByTeam(teamId string) ([]*model.Command, *model.AppError)
|
GetByTeam(teamId string) ([]*model.Command, *model.AppError)
|
||||||
GetByTrigger(teamId string, trigger string) StoreChannel
|
GetByTrigger(teamId string, trigger string) StoreChannel
|
||||||
Delete(commandId string, time int64) *model.AppError
|
Delete(commandId string, time int64) *model.AppError
|
||||||
|
|||||||
@@ -52,15 +52,15 @@ func testCommandStoreGet(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r1 := <-ss.Command().Get(o1.Id); r1.Err != nil {
|
if r1, err := ss.Command().Get(o1.Id); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(*model.Command).CreateAt != o1.CreateAt {
|
if r1.CreateAt != o1.CreateAt {
|
||||||
t.Fatal("invalid returned command")
|
t.Fatal("invalid returned command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := (<-ss.Command().Get("123")).Err; err == nil {
|
if _, err := ss.Command().Get("123"); err == nil {
|
||||||
t.Fatal("Missing id should have failed")
|
t.Fatal("Missing id should have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,10 +150,10 @@ func testCommandStoreDelete(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r1 := <-ss.Command().Get(o1.Id); r1.Err != nil {
|
if r1, err := ss.Command().Get(o1.Id); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(*model.Command).CreateAt != o1.CreateAt {
|
if r1.CreateAt != o1.CreateAt {
|
||||||
t.Fatal("invalid returned command")
|
t.Fatal("invalid returned command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,8 +162,8 @@ func testCommandStoreDelete(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r3 := (<-ss.Command().Get(o1.Id)); r3.Err == nil {
|
if r3, err := ss.Command().Get(o1.Id); err == nil {
|
||||||
t.Log(r3.Data)
|
t.Log(r3)
|
||||||
t.Fatal("Missing id should have failed")
|
t.Fatal("Missing id should have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,10 +181,10 @@ func testCommandStoreDeleteByTeam(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r1 := <-ss.Command().Get(o1.Id); r1.Err != nil {
|
if r1, err := ss.Command().Get(o1.Id); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(*model.Command).CreateAt != o1.CreateAt {
|
if r1.CreateAt != o1.CreateAt {
|
||||||
t.Fatal("invalid returned command")
|
t.Fatal("invalid returned command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,8 +193,8 @@ func testCommandStoreDeleteByTeam(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r3 := (<-ss.Command().Get(o1.Id)); r3.Err == nil {
|
if r3, err := ss.Command().Get(o1.Id); err == nil {
|
||||||
t.Log(r3.Data)
|
t.Log(r3)
|
||||||
t.Fatal("Missing id should have failed")
|
t.Fatal("Missing id should have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,10 +212,10 @@ func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r1 := <-ss.Command().Get(o1.Id); r1.Err != nil {
|
if r1, err := ss.Command().Get(o1.Id); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(*model.Command).CreateAt != o1.CreateAt {
|
if r1.CreateAt != o1.CreateAt {
|
||||||
t.Fatal("invalid returned command")
|
t.Fatal("invalid returned command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,8 +224,8 @@ func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r3 := (<-ss.Command().Get(o1.Id)); r3.Err == nil {
|
if r3, err := ss.Command().Get(o1.Id); err == nil {
|
||||||
t.Log(r3.Data)
|
t.Log(r3)
|
||||||
t.Fatal("Missing id should have failed")
|
t.Fatal("Missing id should have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,19 +53,28 @@ func (_m *CommandStore) Delete(commandId string, time int64) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get provides a mock function with given fields: id
|
// Get provides a mock function with given fields: id
|
||||||
func (_m *CommandStore) Get(id string) store.StoreChannel {
|
func (_m *CommandStore) Get(id string) (*model.Command, *model.AppError) {
|
||||||
ret := _m.Called(id)
|
ret := _m.Called(id)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Command
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) *model.Command); ok {
|
||||||
r0 = rf(id)
|
r0 = rf(id)
|
||||||
} 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(string) *model.AppError); ok {
|
||||||
|
r1 = rf(id)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByTeam provides a mock function with given fields: teamId
|
// GetByTeam provides a mock function with given fields: teamId
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user