Emit Invalidation payloads

This commit is contained in:
David Robertson 2023-09-07 19:54:39 +01:00
parent 777cb357fe
commit f4555f3c22
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
2 changed files with 19 additions and 0 deletions

View File

@ -321,6 +321,10 @@ type AccumulateResult struct {
// TODO: is this redundant---identical to len(TimelineNIDs)?
NumNew int
TimelineNIDs []int64
// ReloadSnapshot is set to the snapshot ID representing the current state of the room, if this Accumulate has
// changed state in a non-incremental fashion. If so, the application should reload its view of this room from the
// given snapshot. Otherwise this is 0.
ReloadFromSnapshot int64
}
// Accumulate internal state from a user's sync response. The timeline order MUST be in the order
@ -507,6 +511,13 @@ func (a *Accumulator) Accumulate(txn *sqlx.Tx, userID, roomID string, prevBatch
}
}
if len(redactTheseEventIDs) > 0 {
// TODO: this is going to send out a cache invalidation when someone redacts a
// message event, which is unnecessary. Can we get eventsTable.Redact to tell us
// if it redacted any state events, and only include a snapID here if so?
result.ReloadFromSnapshot = snapID
}
if err = a.spacesTable.HandleSpaceUpdates(txn, newEvents); err != nil {
return AccumulateResult{}, fmt.Errorf("HandleSpaceUpdates: %s", err)
}

View File

@ -301,6 +301,14 @@ func (h *Handler) Accumulate(ctx context.Context, userID, deviceID, roomID, prev
return err
}
// TODO: does the ordering of this versus V2Accumulate matter here?
if accResult.ReloadFromSnapshot > 0 {
h.v2Pub.Notify(pubsub.ChanV2, &pubsub.V2InvalidateRoom{
RoomID: roomID,
SnapshotID: accResult.ReloadFromSnapshot,
})
}
// We've updated the database. Now tell any pubsub listeners what we learned.
if accResult.NumNew != 0 {
h.v2Pub.Notify(pubsub.ChanV2, &pubsub.V2Accumulate{