MM-53669: Use the cache layer for EmojiStore.GetMultipleByName (#24030)

There was already a cache present for emoji names. But we weren't using
it for the GetMultipleByName method. Now we implement that method
to look up the cache for every emoji name passed.

Secondly, a bigger problem was that we were making the DB call for system
emojis as well. Since system emojis aren't stored in the DB, it would
fall through the cache layer and always make a redundant DB call. In the
profiles, this should up as taking 16% of the total time to serve
a getPostsForChannel API endpoint.

We fix this by filtering the emojis to only custom emojis
before making the call.

https://mattermost.atlassian.net/browse/MM-53669

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2023-07-18 20:27:48 +05:30
коммит произвёл GitHub
родитель b247c6251f
Коммит 3c31629813
13 изменённых файлов: 154 добавлений и 31 удалений

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

@@ -154,26 +154,26 @@ func testEmojiGetMultipleByName(t *testing.T, ss store.Store) {
}()
t.Run("one emoji", func(t *testing.T) {
received, err := ss.Emoji().GetMultipleByName([]string{emojis[0].Name})
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{emojis[0].Name})
require.NoError(t, err, "could not get emoji")
require.Len(t, received, 1, "got incorrect emoji")
require.Equal(t, *received[0], emojis[0], "got incorrect emoji")
})
t.Run("multiple emojis", func(t *testing.T) {
received, err := ss.Emoji().GetMultipleByName([]string{emojis[0].Name, emojis[1].Name, emojis[2].Name})
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{emojis[0].Name, emojis[1].Name, emojis[2].Name})
require.NoError(t, err, "could not get emojis")
require.Len(t, received, 3, "got incorrect emojis")
})
t.Run("one nonexistent emoji", func(t *testing.T) {
received, err := ss.Emoji().GetMultipleByName([]string{"ab"})
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{"ab"})
require.NoError(t, err, "could not get emoji", err)
require.Empty(t, received, "got incorrect emoji")
})
t.Run("multiple emojis with nonexistent names", func(t *testing.T) {
received, err := ss.Emoji().GetMultipleByName([]string{emojis[0].Name, emojis[1].Name, emojis[2].Name, "abcd", "1234"})
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{emojis[0].Name, emojis[1].Name, emojis[2].Name, "abcd", "1234"})
require.NoError(t, err, "could not get emojis")
require.Len(t, received, 3, "got incorrect emojis")
})

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

@@ -108,25 +108,25 @@ func (_m *EmojiStore) GetList(offset int, limit int, sort string) ([]*model.Emoj
return r0, r1
}
// GetMultipleByName provides a mock function with given fields: names
func (_m *EmojiStore) GetMultipleByName(names []string) ([]*model.Emoji, error) {
ret := _m.Called(names)
// GetMultipleByName provides a mock function with given fields: ctx, names
func (_m *EmojiStore) GetMultipleByName(ctx context.Context, names []string) ([]*model.Emoji, error) {
ret := _m.Called(ctx, names)
var r0 []*model.Emoji
var r1 error
if rf, ok := ret.Get(0).(func([]string) ([]*model.Emoji, error)); ok {
return rf(names)
if rf, ok := ret.Get(0).(func(context.Context, []string) ([]*model.Emoji, error)); ok {
return rf(ctx, names)
}
if rf, ok := ret.Get(0).(func([]string) []*model.Emoji); ok {
r0 = rf(names)
if rf, ok := ret.Get(0).(func(context.Context, []string) []*model.Emoji); ok {
r0 = rf(ctx, names)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Emoji)
}
}
if rf, ok := ret.Get(1).(func([]string) error); ok {
r1 = rf(names)
if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok {
r1 = rf(ctx, names)
} else {
r1 = ret.Error(1)
}