mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrate Emoji.Search to Sync by default (#11308)
* Migrate Emoji.Search to Sync by default * Fix indentation
This commit is contained in:
committed by
Jesús Espino
parent
9e9b008f3d
commit
c4b9b3cfd3
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user