diff --git a/app/emoji.go b/app/emoji.go index 2e4e333f7a..9a6d7677ab 100644 --- a/app/emoji.go +++ b/app/emoji.go @@ -229,11 +229,7 @@ func (a *App) SearchEmoji(name string, prefixOnly bool, limit int) ([]*model.Emo return nil, model.NewAppError("SearchEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented) } - result := <-a.Srv.Store.Emoji().Search(name, prefixOnly, limit) - if result.Err != nil { - return nil, result.Err - } - return result.Data.([]*model.Emoji), nil + return a.Srv.Store.Emoji().Search(name, prefixOnly, limit) } func resizeEmojiGif(gifImg *gif.GIF) *gif.GIF { diff --git a/store/sqlstore/emoji_store.go b/store/sqlstore/emoji_store.go index 10af2f7a6e..5d62013a36 100644 --- a/store/sqlstore/emoji_store.go +++ b/store/sqlstore/emoji_store.go @@ -183,30 +183,27 @@ func (es SqlEmojiStore) Delete(id string, time int64) *model.AppError { return nil } -func (es SqlEmojiStore) Search(name string, prefixOnly bool, limit int) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - var emojis []*model.Emoji +func (es SqlEmojiStore) Search(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError) { + var emojis []*model.Emoji - term := "" - if !prefixOnly { - term = "%" - } + term := "" + if !prefixOnly { + term = "%" + } - term += name + "%" + term += name + "%" - if _, err := es.GetReplica().Select(&emojis, - `SELECT - * - FROM - Emoji - WHERE - Name LIKE :Name - AND DeleteAt = 0 - ORDER BY Name - LIMIT :Limit`, map[string]interface{}{"Name": term, "Limit": limit}); err != nil { - result.Err = model.NewAppError("SqlEmojiStore.Search", "store.sql_emoji.get_by_name.app_error", nil, "name="+name+", "+err.Error(), http.StatusInternalServerError) - } else { - result.Data = emojis - } - }) + if _, err := es.GetReplica().Select(&emojis, + `SELECT + * + FROM + Emoji + WHERE + Name LIKE :Name + AND DeleteAt = 0 + ORDER BY Name + LIMIT :Limit`, map[string]interface{}{"Name": term, "Limit": limit}); err != nil { + return nil, model.NewAppError("SqlEmojiStore.Search", "store.sql_emoji.get_by_name.app_error", nil, "name="+name+", "+err.Error(), http.StatusInternalServerError) + } + return emojis, nil } diff --git a/store/store.go b/store/store.go index 83af4d0960..8133b2c8d4 100644 --- a/store/store.go +++ b/store/store.go @@ -462,7 +462,7 @@ type EmojiStore interface { GetMultipleByName(names []string) StoreChannel GetList(offset, limit int, sort string) StoreChannel Delete(id string, time int64) *model.AppError - Search(name string, prefixOnly bool, limit int) StoreChannel + Search(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError) } type StatusStore interface { diff --git a/store/storetest/emoji_store.go b/store/storetest/emoji_store.go index adcad43527..dab90441b8 100644 --- a/store/storetest/emoji_store.go +++ b/store/storetest/emoji_store.go @@ -299,13 +299,13 @@ func testEmojiSearch(t *testing.T, ss store.Store) { shouldFind := []bool{true, false, false, false} - if result := <-ss.Emoji().Search("blargh", true, 100); result.Err != nil { - t.Fatal(result.Err) + if result, err := ss.Emoji().Search("blargh", true, 100); err != nil { + t.Fatal(err) } else { for i, emoji := range emojis { found := false - for _, savedEmoji := range result.Data.([]*model.Emoji) { + for _, savedEmoji := range result { if emoji.Id == savedEmoji.Id { found = true break @@ -317,13 +317,13 @@ func testEmojiSearch(t *testing.T, ss store.Store) { } shouldFind = []bool{true, true, true, false} - if result := <-ss.Emoji().Search("blargh", false, 100); result.Err != nil { - t.Fatal(result.Err) + if result, err := ss.Emoji().Search("blargh", false, 100); err != nil { + t.Fatal(err) } else { for i, emoji := range emojis { found := false - for _, savedEmoji := range result.Data.([]*model.Emoji) { + for _, savedEmoji := range result { if emoji.Id == savedEmoji.Id { found = true break diff --git a/store/storetest/mocks/EmojiStore.go b/store/storetest/mocks/EmojiStore.go index 736aa15f75..d28b2718f8 100644 --- a/store/storetest/mocks/EmojiStore.go +++ b/store/storetest/mocks/EmojiStore.go @@ -137,17 +137,26 @@ func (_m *EmojiStore) Save(emoji *model.Emoji) (*model.Emoji, *model.AppError) { } // Search provides a mock function with given fields: name, prefixOnly, limit -func (_m *EmojiStore) Search(name string, prefixOnly bool, limit int) store.StoreChannel { +func (_m *EmojiStore) Search(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError) { ret := _m.Called(name, prefixOnly, limit) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string, bool, int) store.StoreChannel); ok { + var r0 []*model.Emoji + if rf, ok := ret.Get(0).(func(string, bool, int) []*model.Emoji); ok { r0 = rf(name, prefixOnly, limit) } else { 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, bool, int) *model.AppError); ok { + r1 = rf(name, prefixOnly, limit) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 }