mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-15290: Migrate commandStore.GetByTrigger to sync by default (#10741)
* MM-15290: migrate command.GetByTrigger to sync by default * Fix build * MM-15290: fix go vet issue
This commit is contained in:
committed by
Jesús Espino
parent
9ab3cc9051
commit
6ce3cc6921
@@ -46,11 +46,10 @@ func getCommandFromCommandArg(a *app.App, commandArg string) *model.Command {
|
||||
if team == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Command().GetByTrigger(team.Id, commandPart); result.Err == nil {
|
||||
command = result.Data.(*model.Command)
|
||||
} else {
|
||||
fmt.Println(result.Err.Error())
|
||||
var err *model.AppError
|
||||
command, err = a.Srv.Store.Command().GetByTrigger(team.Id, commandPart)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,23 +81,21 @@ func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppE
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var command model.Command
|
||||
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) {
|
||||
var command model.Command
|
||||
|
||||
var query string
|
||||
if s.DriverName() == "mysql" {
|
||||
query = "SELECT * FROM Commands WHERE TeamId = :TeamId AND `Trigger` = :Trigger AND DeleteAt = 0"
|
||||
} else {
|
||||
query = "SELECT * FROM Commands WHERE TeamId = :TeamId AND \"trigger\" = :Trigger AND DeleteAt = 0"
|
||||
}
|
||||
var query string
|
||||
if s.DriverName() == "mysql" {
|
||||
query = "SELECT * FROM Commands WHERE TeamId = :TeamId AND `Trigger` = :Trigger AND DeleteAt = 0"
|
||||
} else {
|
||||
query = "SELECT * FROM Commands WHERE TeamId = :TeamId AND \"trigger\" = :Trigger AND DeleteAt = 0"
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectOne(&command, query, map[string]interface{}{"TeamId": teamId, "Trigger": trigger}); err != nil {
|
||||
result.Err = model.NewAppError("SqlCommandStore.GetByTrigger", "store.sql_command.get_by_trigger.app_error", nil, "teamId="+teamId+", trigger="+trigger+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if err := s.GetReplica().SelectOne(&command, query, map[string]interface{}{"TeamId": teamId, "Trigger": trigger}); err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.GetByTrigger", "store.sql_command.get_by_trigger.app_error", nil, "teamId="+teamId+", trigger="+trigger+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = &command
|
||||
})
|
||||
return &command, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) Delete(commandId string, time int64) *model.AppError {
|
||||
|
||||
@@ -411,9 +411,9 @@ type WebhookStore interface {
|
||||
|
||||
type CommandStore interface {
|
||||
Save(webhook *model.Command) (*model.Command, *model.AppError)
|
||||
GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError)
|
||||
Get(id string) (*model.Command, *model.AppError)
|
||||
GetByTeam(teamId string) ([]*model.Command, *model.AppError)
|
||||
GetByTrigger(teamId string, trigger string) StoreChannel
|
||||
Delete(commandId string, time int64) *model.AppError
|
||||
PermanentDeleteByTeam(teamId string) *model.AppError
|
||||
PermanentDeleteByUser(userId string) *model.AppError
|
||||
|
||||
@@ -118,11 +118,11 @@ func testCommandStoreGetByTrigger(t *testing.T, ss store.Store) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if r1 := <-ss.Command().GetByTrigger(o1.TeamId, o1.Trigger); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
var r1 *model.Command
|
||||
if r1, err = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r1.Data.(*model.Command).Id != o1.Id {
|
||||
if r1.Id != o1.Id {
|
||||
t.Fatal("invalid returned command")
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func testCommandStoreGetByTrigger(t *testing.T, ss store.Store) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result := <-ss.Command().GetByTrigger(o1.TeamId, o1.Trigger); result.Err == nil {
|
||||
if _, err := ss.Command().GetByTrigger(o1.TeamId, o1.Trigger); err == nil {
|
||||
t.Fatal("no commands should have returned")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ package mocks
|
||||
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import model "github.com/mattermost/mattermost-server/model"
|
||||
import store "github.com/mattermost/mattermost-server/store"
|
||||
|
||||
// CommandStore is an autogenerated mock type for the CommandStore type
|
||||
type CommandStore struct {
|
||||
@@ -103,19 +102,28 @@ func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppEr
|
||||
}
|
||||
|
||||
// GetByTrigger provides a mock function with given fields: teamId, trigger
|
||||
func (_m *CommandStore) GetByTrigger(teamId string, trigger string) store.StoreChannel {
|
||||
func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) {
|
||||
ret := _m.Called(teamId, trigger)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 *model.Command
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.Command); ok {
|
||||
r0 = rf(teamId, trigger)
|
||||
} 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(string, string) *model.AppError); ok {
|
||||
r1 = rf(teamId, trigger)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteByTeam provides a mock function with given fields: teamId
|
||||
|
||||
Reference in New Issue
Block a user