Files
team/server/channels/store/localcachelayer/temporary_post_layer.go
fa07f2c237 MM-67022 - Implement ExpireAt handling for BoR sender to persist countdown (#34796)
* MM-67022 - Implement ExpireAt handling for BoR sender to persist countdown

* enhance read receipt caching, invalidate unread count cache and add GetUnreadCountForPost method

* Use dedicated cache for read receipt unread counts

* fix vet lint

* fix format

* Fix BoR sender countdown after reload in clustered setup

* Fix cache bypass for BoR sender countdown on clustered servers

---------

Co-authored-by: Mattermost Build <[email protected]>
Co-authored-by: Harshil Sharma <[email protected]>
2026-02-09 15:47:27 -05:00

70 lines
2.3 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package localcachelayer
import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
type LocalCacheTemporaryPostStore struct {
store.TemporaryPostStore
rootStore *LocalCacheStore
}
func (s *LocalCacheTemporaryPostStore) handleClusterInvalidateTemporaryPosts(msg *model.ClusterMessage) {
if err := s.rootStore.temporaryPostCache.Purge(); err != nil {
s.rootStore.logger.Error("failed to purge temporary post cache", mlog.Err(err))
}
}
func (s LocalCacheTemporaryPostStore) ClearCaches() {
if err := s.rootStore.temporaryPostCache.Purge(); err != nil {
s.rootStore.logger.Error("failed to purge temporary post cache", mlog.Err(err))
}
if s.rootStore.metrics != nil {
s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.temporaryPostCache.Name())
}
}
func (s LocalCacheTemporaryPostStore) InvalidateTemporaryPost(id string) {
s.rootStore.doInvalidateCacheCluster(s.rootStore.temporaryPostCache, id, nil)
if s.rootStore.metrics != nil {
s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.temporaryPostCache.Name())
}
}
func (s LocalCacheTemporaryPostStore) Save(rctx request.CTX, post *model.TemporaryPost) (*model.TemporaryPost, error) {
defer s.InvalidateTemporaryPost(post.ID)
return s.TemporaryPostStore.Save(rctx, post)
}
func (s LocalCacheTemporaryPostStore) Get(rctx request.CTX, id string, allowFromCache bool) (*model.TemporaryPost, error) {
if !allowFromCache {
return s.TemporaryPostStore.Get(rctx, id, false)
}
var post *model.TemporaryPost
if err := s.rootStore.doStandardReadCache(s.rootStore.temporaryPostCache, id, &post); err == nil {
return post, nil
}
post, err := s.TemporaryPostStore.Get(rctx, id, false)
if err != nil {
return nil, err
}
s.rootStore.doStandardAddToCache(s.rootStore.temporaryPostCache, id, post)
return post, nil
}
func (s LocalCacheTemporaryPostStore) Delete(rctx request.CTX, id string) error {
defer s.InvalidateTemporaryPost(id)
return s.TemporaryPostStore.Delete(rctx, id)
}