merged from gramsrv upstream

This commit is contained in:
onysd 2026-09-01 12:06:31 +03:00
parent 79c64ee916
commit 21a0856587
651 changed files with 54774 additions and 4590 deletions

View file

@ -17,14 +17,16 @@ const retryableChannelTxAttempts = 3
// ChannelStore 用 PostgreSQL 实现 store.ChannelStore。
type ChannelStore struct {
db sqlcgen.DBTX
ids store.ChannelIDAllocator
msgIDs store.ChannelMessageIDAllocator
log *zap.Logger
rowCache *ChannelRowCache
memberCache *ChannelMemberCache
dialogCache *ChannelDialogCache
boostCache *ChannelBoostCache
db sqlcgen.DBTX
ids store.ChannelIDAllocator
msgIDs store.ChannelMessageIDAllocator
log *zap.Logger
rowCache *ChannelRowCache
topMsgCache *ChannelTopMessageCache
memberCache *ChannelMemberCache
dialogCache *ChannelDialogCache
boostCache *ChannelBoostCache
differenceCache *ChannelDifferenceBaseCache
}
// ChannelStoreOption 调整 PostgreSQL ChannelStore 依赖。
@ -53,6 +55,14 @@ func WithChannelRowCache(cache *ChannelRowCache) ChannelStoreOption {
}
}
// WithChannelTopMessageCache injects the shared dialog-top message cache. The
// cache never contains viewer reaction/read overlays.
func WithChannelTopMessageCache(cache *ChannelTopMessageCache) ChannelStoreOption {
return func(s *ChannelStore) {
s.topMsgCache = cache
}
}
// WithChannelMemberCache 注入「频道成员/访问态」进程内缓存。
// 传 nil 等于禁用;事务内仍绕过,提交后由 read model listener 失效。
func WithChannelMemberCache(cache *ChannelMemberCache) ChannelStoreOption {
@ -77,12 +87,25 @@ func WithChannelBoostCache(cache *ChannelBoostCache) ChannelStoreOption {
}
}
// WithChannelDifferenceBaseCache injects the shared immutable event/message
// page cache used by updates.getChannelDifference. Viewer access and overlays
// remain outside this cache.
func WithChannelDifferenceBaseCache(cache *ChannelDifferenceBaseCache) ChannelStoreOption {
return func(s *ChannelStore) {
s.differenceCache = cache
}
}
// cacheActive 报告当前句柄是否可用频道行缓存:仅启用缓存且走连接池(非事务)时。
// 事务内(db != s.db)一律绕过缓存实时读,保证事务读己写。
func (s *ChannelStore) cacheActive(db sqlcgen.DBTX) bool {
return s.rowCache != nil && db == s.db
}
func (s *ChannelStore) topMessageCacheActive(db sqlcgen.DBTX) bool {
return s.topMsgCache != nil && db == s.db
}
func (s *ChannelStore) memberCacheActive(db sqlcgen.DBTX) bool {
return s.memberCache != nil && db == s.db
}