[MM-15193] Migrate "Emoji.Get" to Sync by default (#10801)
* Change emoji.Get to sync * Make emojistore.get sync * Update mocks * Fix build
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
2c0068a288
Коммит
53d0bfe35e
12
app/emoji.go
12
app/emoji.go
@@ -178,11 +178,7 @@ func (a *App) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
|
|||||||
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := <-a.Srv.Store.Emoji().Get(emojiId, false)
|
return a.Srv.Store.Emoji().Get(emojiId, false)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.Emoji), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError) {
|
func (a *App) GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError) {
|
||||||
@@ -214,9 +210,9 @@ func (a *App) GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {
|
func (a *App) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Emoji().Get(emojiId, true)
|
_, storeErr := a.Srv.Store.Emoji().Get(emojiId, true)
|
||||||
if result.Err != nil {
|
if storeErr != nil {
|
||||||
return nil, "", result.Err
|
return nil, "", storeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
img, appErr := a.ReadFile(getEmojiImagePath(emojiId))
|
img, appErr := a.ReadFile(getEmojiImagePath(emojiId))
|
||||||
|
|||||||
@@ -66,45 +66,41 @@ func (es SqlEmojiStore) Save(emoji *model.Emoji) store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (es SqlEmojiStore) Get(id string, allowFromCache bool) store.StoreChannel {
|
func (es SqlEmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
if allowFromCache {
|
||||||
if allowFromCache {
|
if cacheItem, ok := emojiCache.Get(id); ok {
|
||||||
if cacheItem, ok := emojiCache.Get(id); ok {
|
|
||||||
if es.metrics != nil {
|
|
||||||
es.metrics.IncrementMemCacheHitCounter("Emoji")
|
|
||||||
}
|
|
||||||
result.Data = cacheItem.(*model.Emoji)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
if es.metrics != nil {
|
|
||||||
es.metrics.IncrementMemCacheMissCounter("Emoji")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if es.metrics != nil {
|
if es.metrics != nil {
|
||||||
es.metrics.IncrementMemCacheMissCounter("Emoji")
|
es.metrics.IncrementMemCacheHitCounter("Emoji")
|
||||||
}
|
}
|
||||||
|
return cacheItem.(*model.Emoji), nil
|
||||||
}
|
}
|
||||||
|
if es.metrics != nil {
|
||||||
var emoji *model.Emoji
|
es.metrics.IncrementMemCacheMissCounter("Emoji")
|
||||||
|
|
||||||
if err := es.GetReplica().SelectOne(&emoji,
|
|
||||||
`SELECT
|
|
||||||
*
|
|
||||||
FROM
|
|
||||||
Emoji
|
|
||||||
WHERE
|
|
||||||
Id = :Id
|
|
||||||
AND DeleteAt = 0`, map[string]interface{}{"Id": id}); err != nil {
|
|
||||||
result.Err = model.NewAppError("SqlEmojiStore.Get", "store.sql_emoji.get.app_error", nil, "id="+id+", "+err.Error(), http.StatusNotFound)
|
|
||||||
} else {
|
|
||||||
result.Data = emoji
|
|
||||||
|
|
||||||
if allowFromCache {
|
|
||||||
emojiCache.AddWithExpiresInSecs(id, emoji, EMOJI_CACHE_SEC)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
|
if es.metrics != nil {
|
||||||
|
es.metrics.IncrementMemCacheMissCounter("Emoji")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var emoji *model.Emoji
|
||||||
|
|
||||||
|
if err := es.GetReplica().SelectOne(&emoji,
|
||||||
|
`SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
Emoji
|
||||||
|
WHERE
|
||||||
|
Id = :Id
|
||||||
|
AND DeleteAt = 0`, map[string]interface{}{"Id": id}); err != nil {
|
||||||
|
return nil, model.NewAppError("SqlEmojiStore.Get", "store.sql_emoji.get.app_error", nil, "id="+id+", "+err.Error(), http.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
if allowFromCache {
|
||||||
|
emojiCache.AddWithExpiresInSecs(id, emoji, EMOJI_CACHE_SEC)
|
||||||
|
}
|
||||||
|
|
||||||
|
return emoji, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (es SqlEmojiStore) GetByName(name string) store.StoreChannel {
|
func (es SqlEmojiStore) GetByName(name string) store.StoreChannel {
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ type TokenStore interface {
|
|||||||
|
|
||||||
type EmojiStore interface {
|
type EmojiStore interface {
|
||||||
Save(emoji *model.Emoji) StoreChannel
|
Save(emoji *model.Emoji) StoreChannel
|
||||||
Get(id string, allowFromCache bool) StoreChannel
|
Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError)
|
||||||
GetByName(name string) StoreChannel
|
GetByName(name string) StoreChannel
|
||||||
GetMultipleByName(names []string) StoreChannel
|
GetMultipleByName(names []string) StoreChannel
|
||||||
GetList(offset, limit int, sort string) StoreChannel
|
GetList(offset, limit int, sort string) StoreChannel
|
||||||
|
|||||||
@@ -83,20 +83,20 @@ func testEmojiGet(t *testing.T, ss store.Store) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for _, emoji := range emojis {
|
for _, emoji := range emojis {
|
||||||
if result := <-ss.Emoji().Get(emoji.Id, false); result.Err != nil {
|
if _, err := ss.Emoji().Get(emoji.Id, false); err != nil {
|
||||||
t.Fatalf("failed to get emoji with id %v: %v", emoji.Id, result.Err)
|
t.Fatalf("failed to get emoji with id %v: %v", emoji.Id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, emoji := range emojis {
|
for _, emoji := range emojis {
|
||||||
if result := <-ss.Emoji().Get(emoji.Id, true); result.Err != nil {
|
if _, err := ss.Emoji().Get(emoji.Id, true); err != nil {
|
||||||
t.Fatalf("failed to get emoji with id %v: %v", emoji.Id, result.Err)
|
t.Fatalf("failed to get emoji with id %v: %v", emoji.Id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, emoji := range emojis {
|
for _, emoji := range emojis {
|
||||||
if result := <-ss.Emoji().Get(emoji.Id, true); result.Err != nil {
|
if _, err := ss.Emoji().Get(emoji.Id, true); err != nil {
|
||||||
t.Fatalf("failed to get emoji with id %v: %v", emoji.Id, result.Err)
|
t.Fatalf("failed to get emoji with id %v: %v", emoji.Id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,19 +30,28 @@ func (_m *EmojiStore) Delete(id string, time int64) store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get provides a mock function with given fields: id, allowFromCache
|
// Get provides a mock function with given fields: id, allowFromCache
|
||||||
func (_m *EmojiStore) Get(id string, allowFromCache bool) store.StoreChannel {
|
func (_m *EmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError) {
|
||||||
ret := _m.Called(id, allowFromCache)
|
ret := _m.Called(id, allowFromCache)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Emoji
|
||||||
if rf, ok := ret.Get(0).(func(string, bool) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, bool) *model.Emoji); ok {
|
||||||
r0 = rf(id, allowFromCache)
|
r0 = rf(id, allowFromCache)
|
||||||
} 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, bool) *model.AppError); ok {
|
||||||
|
r1 = rf(id, allowFromCache)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByName provides a mock function with given fields: name
|
// GetByName provides a mock function with given fields: name
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user