Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

97 lines
3.1 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package localcachelayer
import (
"bytes"
"context"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/public/shared/mlog"
"github.com/hanzoteam/server/server/v8/channels/store"
)
func (s LocalCachePropertyFieldStore) Create(field *model.PropertyField) (*model.PropertyField, error) {
created, err := s.PropertyFieldStore.Create(field)
if err != nil {
return nil, err
}
s.InvalidateFieldsForGroup(created.GroupID)
return created, nil
}
func (s LocalCachePropertyFieldStore) Update(groupID string, fields []*model.PropertyField, expectedUpdateAts map[string]int64) ([]*model.PropertyField, error) {
updated, err := s.PropertyFieldStore.Update(groupID, fields, expectedUpdateAts)
if err != nil {
return nil, err
}
// The returned slice includes both the requested fields and any linked
// fields the store propagated to. Invalidate each distinct group so all
// affected GetForGroup caches are cleared.
invalidated := make(map[string]bool, len(updated))
for _, field := range updated {
if invalidated[field.GroupID] {
continue
}
invalidated[field.GroupID] = true
s.InvalidateFieldsForGroup(field.GroupID)
}
return updated, nil
}
func (s LocalCachePropertyFieldStore) Delete(groupID string, id string) error {
if err := s.PropertyFieldStore.Delete(groupID, id); err != nil {
return err
}
s.InvalidateFieldsForGroup(groupID)
return nil
}
type LocalCachePropertyFieldStore struct {
store.PropertyFieldStore
rootStore *LocalCacheStore
}
func (s *LocalCachePropertyFieldStore) handleClusterInvalidatePropertyField(msg *model.ClusterMessage) {
if bytes.Equal(msg.Data, clearCacheMessageData) {
if err := s.rootStore.propertyFieldCache.Purge(); err != nil {
s.rootStore.logger.Warn("failed to purge property field cache", mlog.Err(err))
}
} else if err := s.rootStore.propertyFieldCache.Remove(string(msg.Data)); err != nil {
s.rootStore.logger.Warn("failed to remove property field cache entry", mlog.Err(err))
}
}
func (s LocalCachePropertyFieldStore) InvalidateFieldsForGroup(groupID string) {
s.rootStore.doInvalidateCacheCluster(s.rootStore.propertyFieldCache, groupID, nil)
if s.rootStore.metrics != nil {
s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.propertyFieldCache.Name())
}
}
func (s *LocalCachePropertyFieldStore) getFieldsForGroupFromCache(groupID string) ([]*model.PropertyField, bool) {
var fields []*model.PropertyField
if err := s.rootStore.doStandardReadCache(s.rootStore.propertyFieldCache, groupID, &fields); err == nil {
return fields, true
}
return nil, false
}
func (s LocalCachePropertyFieldStore) GetForGroup(ctx context.Context, groupID string) ([]*model.PropertyField, error) {
if fields, ok := s.getFieldsForGroupFromCache(groupID); ok {
return fields, nil
}
fields, err := s.PropertyFieldStore.GetForGroup(ctx, groupID)
if err != nil {
return nil, err
}
s.rootStore.doStandardAddToCache(s.rootStore.propertyFieldCache, groupID, fields)
return fields, nil
}