MCPcopy Index your code
hub / github.com/coder/coder / cacheDurableMessage

Method cacheDurableMessage

coderd/x/chatd/chatd.go:4584–4599  ·  view source on GitHub ↗

cacheDurableMessage stores a recently persisted message event in the per-chat stream state so that same-replica subscribers can catch up from memory instead of the database. The afterMessageID is the message ID that precedes this message (i.e. message.ID - 1).

(chatID uuid.UUID, event codersdk.ChatStreamEvent)

Source from the content-addressed store, hash-verified

4582// from memory instead of the database. The afterMessageID is the
4583// message ID that precedes this message (i.e. message.ID - 1).
4584func (p *Server) cacheDurableMessage(chatID uuid.UUID, event codersdk.ChatStreamEvent) {
4585 state := p.getOrCreateStreamState(chatID)
4586 state.mu.Lock()
4587 defer state.mu.Unlock()
4588
4589 if len(state.durableMessages) >= maxDurableMessageCacheSize {
4590 if evicted := state.durableMessages[0]; evicted.Message != nil {
4591 state.durableEvictedBefore = evicted.Message.ID
4592 }
4593 // Zero the dropped slot so the evicted *ChatMessage is
4594 // GC-eligible; see publishToStream for the same pattern.
4595 state.durableMessages[0] = codersdk.ChatStreamEvent{}
4596 state.durableMessages = state.durableMessages[1:]
4597 }
4598 state.durableMessages = append(state.durableMessages, event)
4599}
4600
4601// getCachedDurableMessages returns cached durable messages with IDs
4602// greater than afterID. Returns nil when the cache has no relevant

Calls 3

LockMethod · 0.45
UnlockMethod · 0.45