MM-32693: Use master when emoji_layer is invalidated (#16951)

We add a map which tracks invalidations to the emoji caches
and use master whenever a fresh item is fetched from DB.

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

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2021-02-26 22:17:51 +05:30
коммит произвёл GitHub
родитель 33c8b0ad73
Коммит 6dcbad049c
14 изменённых файлов: 169 добавлений и 84 удалений

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

@@ -4,6 +4,7 @@
package sqlstore
import (
"context"
"database/sql"
"fmt"
@@ -57,12 +58,12 @@ func (es SqlEmojiStore) Save(emoji *model.Emoji) (*model.Emoji, error) {
return emoji, nil
}
func (es SqlEmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, error) {
return es.getBy("Id", id)
func (es SqlEmojiStore) Get(ctx context.Context, id string, allowFromCache bool) (*model.Emoji, error) {
return es.getBy(ctx, "Id", id)
}
func (es SqlEmojiStore) GetByName(name string, allowFromCache bool) (*model.Emoji, error) {
return es.getBy("Name", name)
func (es SqlEmojiStore) GetByName(ctx context.Context, name string, allowFromCache bool) (*model.Emoji, error) {
return es.getBy(ctx, "Name", name)
}
func (es SqlEmojiStore) GetMultipleByName(names []string) ([]*model.Emoji, error) {
@@ -146,10 +147,10 @@ func (es SqlEmojiStore) Search(name string, prefixOnly bool, limit int) ([]*mode
}
// getBy returns one active (not deleted) emoji, found by any one column (what/key).
func (es SqlEmojiStore) getBy(what, key string) (*model.Emoji, error) {
func (es SqlEmojiStore) getBy(ctx context.Context, what, key string) (*model.Emoji, error) {
var emoji *model.Emoji
err := es.GetReplica().SelectOne(&emoji,
err := es.DBFromContext(ctx).SelectOne(&emoji,
`SELECT
*
FROM