MCPcopy Create free account
hub / github.com/daodst/chat / CalculateAndStoreStateBeforeEvent

Method CalculateAndStoreStateBeforeEvent

roomserver/state/state.go:593–609  ·  view source on GitHub ↗

CalculateAndStoreStateBeforeEvent calculates a snapshot of the state of a room before an event. Stores the snapshot of the state in the database. Returns a numeric ID for the snapshot of the state before the event.

(
	ctx context.Context,
	event *gomatrixserverlib.Event,
	isRejected bool,
)

Source from the content-addressed store, hash-verified

591// Stores the snapshot of the state in the database.
592// Returns a numeric ID for the snapshot of the state before the event.
593func (v *StateResolution) CalculateAndStoreStateBeforeEvent(
594 ctx context.Context,
595 event *gomatrixserverlib.Event,
596 isRejected bool,
597) (types.StateSnapshotNID, error) {
598 span, ctx := opentracing.StartSpanFromContext(ctx, "StateResolution.CalculateAndStoreStateBeforeEvent")
599 defer span.Finish()
600
601 // Load the state at the prev events.
602 prevStates, err := v.db.StateAtEventIDs(ctx, event.PrevEventIDs())
603 if err != nil {
604 return 0, err
605 }
606
607 // The state before this event will be the state after the events that came before it.
608 return v.CalculateAndStoreStateAfterEvents(ctx, prevStates)
609}
610
611// CalculateAndStoreStateAfterEvents finds the room state after the given events.
612// Stores the resulting state in the database and returns a numeric ID for that snapshot.

Callers 1

calculateAndSetStateMethod · 0.95

Calls 3

PrevEventIDsMethod · 0.80
StateAtEventIDsMethod · 0.65

Tested by

no test coverage detected