cache

package
v1.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInCache

func NewInCache(db messaging.Store) messaging.Store

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache wraps a messaging.Store, caching the largest message ID seen per chat to short-circuit existence checks. Each chat has its own gapless message ID sequence starting at 1, and messages are never removed (a deletion is a tombstone, still a real message). So if id <= the largest known ID, every ID up to it — including id — exists, and MessageExists can answer true without touching the backing store.

The cached value is only ever a lower bound on the true maximum: it is seeded from IDs the backing store has confirmed (a PutMessage result, or a positive MessageExists), so a true cache answer is always correct even across multiple server instances. A miss (id above the cached bound, or no entry yet) falls through to the backing store, and a confirmed existing id then raises the bound. The rest of the store is passed straight through.

func (*Cache) AddReaction

func (c *Cache) AddReaction(
	ctx context.Context,
	chatID *commonpb.ChatId,
	messageID *messagingpb.MessageId,
	userID *commonpb.UserId,
	emoji string,
	ts time.Time,
) (*messaging.Reaction, bool, bool, error)

func (*Cache) AdvancePointer

func (c *Cache) AdvancePointer(
	ctx context.Context,
	chatID *commonpb.ChatId,
	userID *commonpb.UserId,
	pointerType messagingpb.Pointer_Type,
	newValue *messagingpb.MessageId,
) (*messagingpb.Pointer, bool, error)

func (*Cache) DeleteMessage

func (c *Cache) DeleteMessage(
	ctx context.Context,
	chatID *commonpb.ChatId,
	messageID *messagingpb.MessageId,
	deletedBy *commonpb.UserId,
	deletedTs time.Time,
	expectedEventSeq uint64,
) (*messaging.Message, error)

func (*Cache) EditMessage added in v1.19.0

func (c *Cache) EditMessage(
	ctx context.Context,
	chatID *commonpb.ChatId,
	messageID *messagingpb.MessageId,
	content []*messagingpb.Content,
	editedTs time.Time,
	expectedEventSeq uint64,
) (*messaging.Message, error)

func (*Cache) GetEventDelta

func (c *Cache) GetEventDelta(ctx context.Context, chatID *commonpb.ChatId, afterEventSeq, headEventSeq uint64, limit int) ([]*messaging.Message, uint64, error)

func (*Cache) GetLatestEventSequence

func (c *Cache) GetLatestEventSequence(ctx context.Context, chatID *commonpb.ChatId) (uint64, error)

func (*Cache) GetLatestEventSequencesForChats added in v1.19.0

func (c *Cache) GetLatestEventSequencesForChats(ctx context.Context, chatIDs []*commonpb.ChatId) (map[string]uint64, error)

func (*Cache) GetMessage

func (c *Cache) GetMessage(ctx context.Context, chatID *commonpb.ChatId, messageID *messagingpb.MessageId) (*messaging.Message, error)

func (*Cache) GetMessages

func (c *Cache) GetMessages(ctx context.Context, chatID *commonpb.ChatId, opts ...database.QueryOption) ([]*messaging.Message, error)

func (*Cache) GetMessagesByRefs

func (c *Cache) GetMessagesByRefs(ctx context.Context, refs []messaging.MessageRef) ([]*messaging.Message, error)

func (*Cache) GetPointers

func (c *Cache) GetPointers(ctx context.Context, chatID *commonpb.ChatId) ([]*messagingpb.Pointer, error)

func (*Cache) GetPointersForChats

func (c *Cache) GetPointersForChats(ctx context.Context, refs []messaging.PointerRef) (map[string][]*messagingpb.Pointer, error)

func (*Cache) GetReactionSummaries

func (c *Cache) GetReactionSummaries(
	ctx context.Context,
	chatID *commonpb.ChatId,
	opts ...database.QueryOption,
) ([]*messaging.ReactionSummary, error)

func (*Cache) GetReactionSummariesByRefs

func (c *Cache) GetReactionSummariesByRefs(
	ctx context.Context,
	chatID *commonpb.ChatId,
	messageIDs []*messagingpb.MessageId,
) ([]*messaging.ReactionSummary, error)

func (*Cache) GetReactionSummary

func (c *Cache) GetReactionSummary(
	ctx context.Context,
	chatID *commonpb.ChatId,
	messageID *messagingpb.MessageId,
) ([]*messaging.Reaction, error)

func (*Cache) GetReactors

func (c *Cache) GetReactors(
	ctx context.Context,
	chatID *commonpb.ChatId,
	messageID *messagingpb.MessageId,
	emoji string,
	consistent bool,
	opts ...database.QueryOption,
) ([]*messaging.Reactor, bool, error)

func (*Cache) GetSelfReactions

func (c *Cache) GetSelfReactions(
	ctx context.Context,
	chatID *commonpb.ChatId,
	userID *commonpb.UserId,
	refs []messaging.ReactionRef,
) ([]messaging.ReactionRef, error)

func (*Cache) MessageExists

func (c *Cache) MessageExists(ctx context.Context, chatID *commonpb.ChatId, messageID *messagingpb.MessageId) (bool, error)

func (*Cache) PutMessage

func (c *Cache) PutMessage(
	ctx context.Context,
	chatID *commonpb.ChatId,
	senderID *commonpb.UserId,
	content []*messagingpb.Content,
	ts time.Time,
	clientMessageID *messagingpb.ClientMessageId,
	countsTowardUnread bool,
) (*messaging.Message, bool, error)

func (*Cache) RemoveReaction

func (c *Cache) RemoveReaction(
	ctx context.Context,
	chatID *commonpb.ChatId,
	messageID *messagingpb.MessageId,
	userID *commonpb.UserId,
	emoji string,
) (*messaging.Reaction, bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL