[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
@@ -66,45 +66,41 @@ func (es SqlEmojiStore) Save(emoji *model.Emoji) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (es SqlEmojiStore) Get(id string, allowFromCache bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if allowFromCache {
|
||||
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 {
|
||||
func (es SqlEmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError) {
|
||||
if allowFromCache {
|
||||
if cacheItem, ok := emojiCache.Get(id); ok {
|
||||
if es.metrics != nil {
|
||||
es.metrics.IncrementMemCacheMissCounter("Emoji")
|
||||
es.metrics.IncrementMemCacheHitCounter("Emoji")
|
||||
}
|
||||
return cacheItem.(*model.Emoji), nil
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
if es.metrics != nil {
|
||||
es.metrics.IncrementMemCacheMissCounter("Emoji")
|
||||
}
|
||||
})
|
||||
} 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 {
|
||||
|
||||
Ссылка в новой задаче
Block a user