Migrate Emoji.GetMultipleByName to Sync by default (#11315)

* Migrate Emoji.GetMultipleByName to Sync by default

* Fix indentation

* Fixing mocks
Этот коммит содержится в:
Shobhit Gupta
2019-07-02 13:26:09 -07:00
коммит произвёл Jesús Espino
родитель b55b9a3d97
Коммит b138d4b8c4
5 изменённых файлов: 42 добавлений и 41 удалений

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

@@ -194,11 +194,7 @@ func (a *App) GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.App
return nil, model.NewAppError("GetMultipleEmojiByName", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetMultipleEmojiByName", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
if result := <-a.Srv.Store.Emoji().GetMultipleByName(names); result.Err != nil { return a.Srv.Store.Emoji().GetMultipleByName(names)
return nil, result.Err
} else {
return result.Data.([]*model.Emoji), nil
}
} }
func (a *App) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) { func (a *App) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {

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

@@ -123,8 +123,7 @@ func (es SqlEmojiStore) GetByName(name string) (*model.Emoji, *model.AppError) {
return emoji, nil return emoji, nil
} }
func (es SqlEmojiStore) GetMultipleByName(names []string) store.StoreChannel { func (es SqlEmojiStore) GetMultipleByName(names []string) ([]*model.Emoji, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
keys, params := MapStringsToQueryParams(names, "Emoji") keys, params := MapStringsToQueryParams(names, "Emoji")
var emojis []*model.Emoji var emojis []*model.Emoji
@@ -137,11 +136,9 @@ func (es SqlEmojiStore) GetMultipleByName(names []string) store.StoreChannel {
WHERE WHERE
Name IN `+keys+` Name IN `+keys+`
AND DeleteAt = 0`, params); err != nil { AND DeleteAt = 0`, params); err != nil {
result.Err = model.NewAppError("SqlEmojiStore.GetByName", "store.sql_emoji.get_by_name.app_error", nil, fmt.Sprintf("names=%v, %v", names, err.Error()), http.StatusInternalServerError) return nil, model.NewAppError("SqlEmojiStore.GetByName", "store.sql_emoji.get_by_name.app_error", nil, fmt.Sprintf("names=%v, %v", names, err.Error()), http.StatusInternalServerError)
} else {
result.Data = emojis
} }
}) return emojis, nil
} }
func (es SqlEmojiStore) GetList(offset, limit int, sort string) ([]*model.Emoji, *model.AppError) { func (es SqlEmojiStore) GetList(offset, limit int, sort string) ([]*model.Emoji, *model.AppError) {

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

@@ -461,7 +461,7 @@ type EmojiStore interface {
Save(emoji *model.Emoji) (*model.Emoji, *model.AppError) Save(emoji *model.Emoji) (*model.Emoji, *model.AppError)
Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError) Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError)
GetByName(name string) (*model.Emoji, *model.AppError) GetByName(name string) (*model.Emoji, *model.AppError)
GetMultipleByName(names []string) StoreChannel GetMultipleByName(names []string) ([]*model.Emoji, *model.AppError)
GetList(offset, limit int, sort string) ([]*model.Emoji, *model.AppError) GetList(offset, limit int, sort string) ([]*model.Emoji, *model.AppError)
Delete(id string, time int64) *model.AppError Delete(id string, time int64) *model.AppError
Search(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError) Search(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError)

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

@@ -169,33 +169,33 @@ func testEmojiGetMultipleByName(t *testing.T, ss store.Store) {
}() }()
t.Run("one emoji", func(t *testing.T) { t.Run("one emoji", func(t *testing.T) {
if result := <-ss.Emoji().GetMultipleByName([]string{emojis[0].Name}); result.Err != nil { if received, err := ss.Emoji().GetMultipleByName([]string{emojis[0].Name}); err != nil {
t.Fatal("could not get emoji", result.Err) t.Fatal("could not get emoji", err)
} else if received := result.Data.([]*model.Emoji); len(received) != 1 || *received[0] != emojis[0] { } else if len(received) != 1 || *received[0] != emojis[0] {
t.Fatal("got incorrect emoji") t.Fatal("got incorrect emoji")
} }
}) })
t.Run("multiple emojis", func(t *testing.T) { t.Run("multiple emojis", func(t *testing.T) {
if result := <-ss.Emoji().GetMultipleByName([]string{emojis[0].Name, emojis[1].Name, emojis[2].Name}); result.Err != nil { if received, err := ss.Emoji().GetMultipleByName([]string{emojis[0].Name, emojis[1].Name, emojis[2].Name}); err != nil {
t.Fatal("could not get emojis", result.Err) t.Fatal("could not get emojis", err)
} else if received := result.Data.([]*model.Emoji); len(received) != 3 { } else if len(received) != 3 {
t.Fatal("got incorrect emojis") t.Fatal("got incorrect emojis")
} }
}) })
t.Run("one nonexistent emoji", func(t *testing.T) { t.Run("one nonexistent emoji", func(t *testing.T) {
if result := <-ss.Emoji().GetMultipleByName([]string{"ab"}); result.Err != nil { if received, err := ss.Emoji().GetMultipleByName([]string{"ab"}); err != nil {
t.Fatal("could not get emoji", result.Err) t.Fatal("could not get emoji", err)
} else if received := result.Data.([]*model.Emoji); len(received) != 0 { } else if len(received) != 0 {
t.Fatal("got incorrect emoji") t.Fatal("got incorrect emoji")
} }
}) })
t.Run("multiple emojis with nonexistent names", func(t *testing.T) { t.Run("multiple emojis with nonexistent names", func(t *testing.T) {
if result := <-ss.Emoji().GetMultipleByName([]string{emojis[0].Name, emojis[1].Name, emojis[2].Name, "abcd", "1234"}); result.Err != nil { if received, err := ss.Emoji().GetMultipleByName([]string{emojis[0].Name, emojis[1].Name, emojis[2].Name, "abcd", "1234"}); err != nil {
t.Fatal("could not get emojis", result.Err) t.Fatal("could not get emojis", err)
} else if received := result.Data.([]*model.Emoji); len(received) != 3 { } else if len(received) != 3 {
t.Fatal("got incorrect emojis") t.Fatal("got incorrect emojis")
} }
}) })

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

@@ -6,7 +6,6 @@ package mocks
import mock "github.com/stretchr/testify/mock" import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model" import model "github.com/mattermost/mattermost-server/model"
import store "github.com/mattermost/mattermost-server/store"
// EmojiStore is an autogenerated mock type for the EmojiStore type // EmojiStore is an autogenerated mock type for the EmojiStore type
type EmojiStore struct { type EmojiStore struct {
@@ -105,19 +104,28 @@ func (_m *EmojiStore) GetList(offset int, limit int, sort string) ([]*model.Emoj
} }
// GetMultipleByName provides a mock function with given fields: names // GetMultipleByName provides a mock function with given fields: names
func (_m *EmojiStore) GetMultipleByName(names []string) store.StoreChannel { func (_m *EmojiStore) GetMultipleByName(names []string) ([]*model.Emoji, *model.AppError) {
ret := _m.Called(names) ret := _m.Called(names)
var r0 store.StoreChannel var r0 []*model.Emoji
if rf, ok := ret.Get(0).(func([]string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func([]string) []*model.Emoji); ok {
r0 = rf(names) r0 = rf(names)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).([]*model.Emoji)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func([]string) *model.AppError); ok {
r1 = rf(names)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// Save provides a mock function with given fields: emoji // Save provides a mock function with given fields: emoji