aboutsummaryrefslogtreecommitdiff
path: root/roomserver/state
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-08-01 14:11:00 +0100
committerGitHub <noreply@github.com>2022-08-01 14:11:00 +0100
commit05c83923e3bf24fa7def55a14ac096cdff3a3882 (patch)
tree3ee6bca7393990e75b83971a23611f6982998d59 /roomserver/state
parentc7f7aec4d07d59120d37d5b16a900f6d608a75c4 (diff)
Optimise checking other servers allowed to see events (#2596)
* Try optimising checking if server is allowed to see event * Fix error * Handle case where snapshot NID is 0 * Fix query * Update SQL * Clean up `CheckServerAllowedToSeeEvent` * Not supported on SQLite * Maybe placate the unit tests * Review comments
Diffstat (limited to 'roomserver/state')
-rw-r--r--roomserver/state/state.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/roomserver/state/state.go b/roomserver/state/state.go
index d1d24b09..ca0c69f2 100644
--- a/roomserver/state/state.go
+++ b/roomserver/state/state.go
@@ -124,6 +124,29 @@ func (v *StateResolution) LoadStateAtEvent(
return stateEntries, nil
}
+// LoadStateAtEvent loads the full state of a room before a particular event.
+func (v *StateResolution) LoadStateAtEventForHistoryVisibility(
+ ctx context.Context, eventID string,
+) ([]types.StateEntry, error) {
+ span, ctx := opentracing.StartSpanFromContext(ctx, "StateResolution.LoadStateAtEvent")
+ defer span.Finish()
+
+ snapshotNID, err := v.db.SnapshotNIDFromEventID(ctx, eventID)
+ if err != nil {
+ return nil, fmt.Errorf("LoadStateAtEvent.SnapshotNIDFromEventID failed for event %s : %w", eventID, err)
+ }
+ if snapshotNID == 0 {
+ return nil, fmt.Errorf("LoadStateAtEvent.SnapshotNIDFromEventID(%s) returned 0 NID, was this event stored?", eventID)
+ }
+
+ stateEntries, err := v.LoadStateAtSnapshot(ctx, snapshotNID)
+ if err != nil {
+ return nil, err
+ }
+
+ return stateEntries, nil
+}
+
// LoadCombinedStateAfterEvents loads a snapshot of the state after each of the events
// and combines those snapshots together into a single list. At this point it is
// possible to run into duplicate (type, state key) tuples.