Documentation
¶
Index ¶
- func NewInCache(db chat.Store) chat.Store
- type Cache
- func (c *Cache) AddGroupMembers(ctx context.Context, chatID *commonpb.ChatId, userIDs []*commonpb.UserId) (bool, chat.RosterSummary, error)
- func (c *Cache) AdmitFromLobby(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, ...) (bool, chat.RosterSummary, error)
- func (c *Cache) AdvanceLastMessage(ctx context.Context, chatID *commonpb.ChatId, messageID *messagingpb.MessageId, ...) (bool, []*commonpb.UserId, error)
- func (c *Cache) ClaimHoldingsRefresh(ctx context.Context, chatID *commonpb.ChatId, asOf, until time.Time) (bool, error)
- func (c *Cache) ClearMute(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (chat.ViewerState, bool, error)
- func (c *Cache) EditGroup(ctx context.Context, chatID *commonpb.ChatId, edit chat.GroupEdit) error
- func (c *Cache) EnqueueHoldingsRefresh(ctx context.Context, chatID *commonpb.ChatId, mint *commonpb.PublicKey, ...) (bool, error)
- func (c *Cache) EnterLobby(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, ...) (chat.LobbyEntry, bool, error)
- func (c *Cache) GetActiveSenders(ctx context.Context, chatID *commonpb.ChatId, limit int) ([]chat.RecentSender, error)
- func (c *Cache) GetChatByID(ctx context.Context, chatID *commonpb.ChatId) (*chat.Chat, error)
- func (c *Cache) GetDmFeedPage(ctx context.Context, userID *commonpb.UserId, chatType chatpb.ChatType, ...) ([]*chat.Chat, error)
- func (c *Cache) GetDueHoldingsRefreshes(ctx context.Context, asOf time.Time, limit int) ([]chat.HoldingsRefresh, error)
- func (c *Cache) GetFeaturedGroups(ctx context.Context, userID *commonpb.UserId) (chat.FeaturedGroups, error)
- func (c *Cache) GetGroupChatsByID(ctx context.Context, chatIDs []*commonpb.ChatId) (map[string]*chat.Chat, error)
- func (c *Cache) GetGroupChatsForUser(ctx context.Context, userID *commonpb.UserId) ([]*chat.Chat, error)
- func (c *Cache) GetGroupChatsForUserByIDs(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) ([]*chat.Chat, error)
- func (c *Cache) GetGroupHoldings(ctx context.Context, chatIDs []*commonpb.ChatId) (map[string]chat.GroupHoldings, error)
- func (c *Cache) GetGroupMemberRecords(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) (map[string]chat.GroupMember, error)
- func (c *Cache) GetGroupMembersByID(ctx context.Context, chatID *commonpb.ChatId, userIDs []*commonpb.UserId) (map[string]chat.GroupMember, error)
- func (c *Cache) GetGroupMembersPage(ctx context.Context, chatID *commonpb.ChatId, after *commonpb.UserId, ...) (chat.MembersPage, error)
- func (c *Cache) GetGroupMembershipsForUser(ctx context.Context, userID *commonpb.UserId) ([]chat.GroupMembership, error)
- func (c *Cache) GetGroupRoster(ctx context.Context, chatID *commonpb.ChatId) (chat.RosterSummary, []chat.GroupMember, error)
- func (c *Cache) GetGroupRosterPage(ctx context.Context, chatID *commonpb.ChatId, after *chat.RosterPosition, ...) ([]chat.GroupMember, error)
- func (c *Cache) GetGroupRosterSummaries(ctx context.Context, chatIDs []*commonpb.ChatId) (map[string]chat.RosterSummary, error)
- func (c *Cache) GetGroupRosterSummary(ctx context.Context, chatID *commonpb.ChatId) (chat.RosterSummary, error)
- func (c *Cache) GetGroupRules(ctx context.Context, chatID *commonpb.ChatId) (chat.ChatRules, error)
- func (c *Cache) GetKeyEnvelope(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (chat.KeyEnvelope, error)
- func (c *Cache) GetLastSentAt(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (time.Time, bool, error)
- func (c *Cache) GetLobbyEntries(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) (map[string]chat.LobbyEntry, error)
- func (c *Cache) GetLobbyPage(ctx context.Context, chatID *commonpb.ChatId, after *chat.LobbyPosition, ...) ([]chat.LobbyEntry, error)
- func (c *Cache) GetMembers(ctx context.Context, chatID *commonpb.ChatId) ([]*commonpb.UserId, error)
- func (c *Cache) GetMutedCount(ctx context.Context, chatID *commonpb.ChatId) (uint64, error)
- func (c *Cache) GetMutedUsers(ctx context.Context, chatID *commonpb.ChatId, now time.Time, limit int) ([]*commonpb.UserId, error)
- func (c *Cache) GetMutedUsersPage(ctx context.Context, chatID *commonpb.ChatId, now time.Time, ...) ([]*commonpb.UserId, error)
- func (c *Cache) GetRecentSenders(ctx context.Context, chatID *commonpb.ChatId, limit int) ([]chat.RecentSender, error)
- func (c *Cache) GetTopGroupsByHoldings(ctx context.Context, mint *commonpb.PublicKey, limit int) ([]chat.GroupHoldings, error)
- func (c *Cache) GetViewerStates(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) (map[string]chat.ViewerState, error)
- func (c *Cache) IsMember(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (bool, error)
- func (c *Cache) LeaveLobby(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (bool, error)
- func (c *Cache) PutChat(ctx context.Context, ch *chat.Chat) error
- func (c *Cache) PutGroupHoldings(ctx context.Context, h chat.GroupHoldings) (bool, error)
- func (c *Cache) RecordSend(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, ...) (bool, error)
- func (c *Cache) RemoveGroupMember(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, ...) (bool, chat.RosterSummary, error)
- func (c *Cache) RescheduleHoldingsRefresh(ctx context.Context, chatID *commonpb.ChatId, dueAt time.Time, attempts uint32) error
- func (c *Cache) SetFeaturedGroups(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) (chat.FeaturedGroups, bool, error)
- func (c *Cache) SetGroupPicture(ctx context.Context, chatID *commonpb.ChatId, blobID *blobpb.BlobId) error
- func (c *Cache) SetKeyEnvelope(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, ...) (chat.KeyEnvelope, error)
- func (c *Cache) SetMute(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, ...) (chat.ViewerState, bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache wraps a chat.Store, caching what is fixed at a chat's creation and so can never go stale: DM membership checks, a DM's member list, and a group's participation rules with its creator. A DM's membership never changes, so a confirmed DM member, and the DM's member pair, are safe to cache. Group membership is mutable — and can be mutated by other processes, which this cache can never observe — so group membership checks and member lists always defer to the backing store. The rest of the store is passed straight through, viewer state, activity reads and key envelopes included: a user's state is theirs to change at any time, a group's recent senders change with every send, and both reads are already one strongly consistent query, so nothing of either is held.
One thing is held that is not fixed at creation: a lower bound on each activity record, so a throttled send costs no store request (see RecordSend). It can be out of date but never wrong in the direction that matters, because the record only moves forward.
func (*Cache) AddGroupMembers ¶ added in v1.26.0
func (*Cache) AdmitFromLobby ¶ added in v1.34.0
func (*Cache) AdvanceLastMessage ¶
func (*Cache) ClaimHoldingsRefresh ¶ added in v1.35.0
func (*Cache) EnqueueHoldingsRefresh ¶ added in v1.35.0
func (*Cache) EnterLobby ¶ added in v1.34.0
func (c *Cache) EnterLobby(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, limits chat.LobbyLimits) (chat.LobbyEntry, bool, error)
The lobby methods pass through: a lobby moves with every entry and admission, from any process, and every read of one is already a single query.
func (*Cache) GetActiveSenders ¶ added in v1.34.0
func (*Cache) GetChatByID ¶
func (*Cache) GetDmFeedPage ¶
func (*Cache) GetDueHoldingsRefreshes ¶ added in v1.35.0
func (*Cache) GetFeaturedGroups ¶ added in v1.34.0
func (*Cache) GetGroupChatsByID ¶ added in v1.34.0
func (c *Cache) GetGroupChatsByID(ctx context.Context, chatIDs []*commonpb.ChatId) (map[string]*chat.Chat, error)
GetGroupChatsByID passes through: a group's record changes with every edit and send, and only what is fixed at creation is held here.
func (*Cache) GetGroupChatsForUser ¶ added in v1.30.0
func (*Cache) GetGroupChatsForUserByIDs ¶ added in v1.30.0
func (*Cache) GetGroupHoldings ¶ added in v1.35.0
func (*Cache) GetGroupMemberRecords ¶ added in v1.32.0
func (*Cache) GetGroupMembersByID ¶ added in v1.34.0
func (*Cache) GetGroupMembersPage ¶ added in v1.32.0
func (c *Cache) GetGroupMembersPage(ctx context.Context, chatID *commonpb.ChatId, after *commonpb.UserId, limit int) (chat.MembersPage, error)
GetGroupMembersPage passes through: a group's roster is mutable and never cached here, as for GetMembers.
func (*Cache) GetGroupMembershipsForUser ¶ added in v1.30.0
func (c *Cache) GetGroupMembershipsForUser(ctx context.Context, userID *commonpb.UserId) ([]chat.GroupMembership, error)
Never cached, for the same reason group IsMember checks are not: group membership is mutable from other processes.
func (*Cache) GetGroupRoster ¶ added in v1.32.0
func (c *Cache) GetGroupRoster(ctx context.Context, chatID *commonpb.ChatId) (chat.RosterSummary, []chat.GroupMember, error)
GetGroupRoster, GetGroupRosterPage and GetGroupMemberRecords pass through likewise: each is a read of the mutable membership records.
func (*Cache) GetGroupRosterPage ¶ added in v1.32.0
func (*Cache) GetGroupRosterSummaries ¶ added in v1.30.0
func (*Cache) GetGroupRosterSummary ¶ added in v1.30.0
func (*Cache) GetGroupRules ¶ added in v1.30.0
GetGroupRules is cached, including the absence of rules (a nil Rules), so a group without any is read once too. Rules, the creator and whether the group is private are fixed at creation (see chat.Store), so a cached entry is never stale: if any ever becomes mutable, this needs invalidation on write. That holds only while all are written with the group: a creator backfilled onto a legacy group, or IsCreatorOnlySpeaker, MinimumSpeakerBalance or IsPrivate set on a group that already exists, reaches a process that has read the group only when it restarts. A cached entry is shared by every caller and must be treated as read-only. Errors — including ErrChatNotFound, since the group may be created later — are not cached.
func (*Cache) GetKeyEnvelope ¶ added in v1.34.0
func (*Cache) GetLastSentAt ¶ added in v1.34.0
func (*Cache) GetLobbyEntries ¶ added in v1.34.0
func (*Cache) GetLobbyPage ¶ added in v1.34.0
func (*Cache) GetMembers ¶
func (c *Cache) GetMembers(ctx context.Context, chatID *commonpb.ChatId) ([]*commonpb.UserId, error)
GetMembers is cached for a DM: its member pair is fixed at creation, so a list once read is never stale. It is the read behind every DM broadcast (a message, a pointer advance, a reaction, typing), which otherwise costs a store read per event just to find the peer. A group's roster is mutable, so a group's list always defers to the backing store, as IsMember does. Errors — including ErrChatNotFound, since the DM may be created later — are not cached. The caller gets its own copy, so the cached list is never mutated through a result.
func (*Cache) GetMutedCount ¶ added in v1.32.0
func (*Cache) GetMutedUsers ¶ added in v1.32.0
func (*Cache) GetMutedUsersPage ¶ added in v1.32.0
func (*Cache) GetRecentSenders ¶ added in v1.34.0
func (*Cache) GetTopGroupsByHoldings ¶ added in v1.35.0
func (*Cache) GetViewerStates ¶ added in v1.32.0
func (*Cache) LeaveLobby ¶ added in v1.34.0
func (*Cache) PutGroupHoldings ¶ added in v1.35.0
The holdings methods pass through: a snapshot is replaced by a refresh in any process, and its readers are batched already.
func (*Cache) RecordSend ¶ added in v1.34.0
func (c *Cache) RecordSend(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, sentAt time.Time) (bool, error)
RecordSend answers a throttled send itself, with no store request: the backing store reads the record to find a send throttled (see chat.Store.RecordSend), so leaving the throttle to it would cost a read per message. Each send this process saw recorded is held for ActivityRecordInterval, keyed by (group, user), and a send the interval has not yet cleared since it is answered false, exactly as the store would answer it: the record only moves forward, so it holds at least what was seen recorded here, whatever other processes have written since. A send this process has not seen within the interval, or one the store refused, goes to the store, so a stale entry can cost a store request but never skip a record. Each process throttles on its own, so a user's sends spread across several processes cost up to one store request per process per interval, of which the store records one. A send the store would reject outright (a DM ID, a time before the epoch) is never answered here.
func (*Cache) RemoveGroupMember ¶ added in v1.26.0
func (*Cache) RescheduleHoldingsRefresh ¶ added in v1.35.0
func (*Cache) SetFeaturedGroups ¶ added in v1.34.0
func (c *Cache) SetFeaturedGroups(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) (chat.FeaturedGroups, bool, error)
The featured groups methods pass through: a list is read once per profile view, is one query, and changes from any process.
func (*Cache) SetGroupPicture ¶ added in v1.30.0
func (*Cache) SetKeyEnvelope ¶ added in v1.34.0
func (c *Cache) SetKeyEnvelope(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, envelope chat.KeyEnvelope) (chat.KeyEnvelope, error)
The key envelope methods pass through: an envelope is read once per chat per install, and one a user wrapped for themself replaces the one they were admitted with, so there is nothing worth holding and something to get wrong.