aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/shared/storage.go
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/storage/shared/storage.go
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/storage/shared/storage.go')
-rw-r--r--roomserver/storage/shared/storage.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index 2f9932ff..daac4e82 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -988,6 +988,38 @@ func (d *Database) loadEvent(ctx context.Context, eventID string) *types.Event {
return &evs[0]
}
+func (d *Database) GetHistoryVisibilityState(ctx context.Context, roomInfo *types.RoomInfo, eventID string, domain string) ([]*gomatrixserverlib.Event, error) {
+ eventStates, err := d.EventsTable.BulkSelectStateAtEventByID(ctx, nil, []string{eventID})
+ if err != nil {
+ return nil, err
+ }
+ stateSnapshotNID := eventStates[0].BeforeStateSnapshotNID
+ if stateSnapshotNID == 0 {
+ return nil, nil
+ }
+ eventNIDs, err := d.StateSnapshotTable.BulkSelectStateForHistoryVisibility(ctx, nil, stateSnapshotNID, domain)
+ if err != nil {
+ return nil, err
+ }
+ eventIDs, _ := d.EventsTable.BulkSelectEventID(ctx, nil, eventNIDs)
+ if err != nil {
+ eventIDs = map[types.EventNID]string{}
+ }
+ events := make([]*gomatrixserverlib.Event, 0, len(eventNIDs))
+ for _, eventNID := range eventNIDs {
+ data, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{eventNID})
+ if err != nil {
+ return nil, err
+ }
+ ev, err := gomatrixserverlib.NewEventFromTrustedJSONWithEventID(eventIDs[eventNID], data[0].EventJSON, false, roomInfo.RoomVersion)
+ if err != nil {
+ return nil, err
+ }
+ events = append(events, ev)
+ }
+ return events, nil
+}
+
// GetStateEvent returns the current state event of a given type for a given room with a given state key
// If no event could be found, returns nil
// If there was an issue during the retrieval, returns an error