aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/shared
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-11-01 16:07:17 +0100
committerGitHub <noreply@github.com>2022-11-01 15:07:17 +0000
commit2acc1d65fb360f8a68cdc2e0e154365f2e7353d3 (patch)
treeb6d4079b13a64aad0f25dbcdd38d01b3fbb2449b /roomserver/storage/shared
parent0b21cb78aa717e91fbed9efc1ffbfe770bd8c37b (diff)
Optimize history visibility checks (#2848)
This optimizes history visibility checks by (mostly) avoiding database hits. Possibly solves https://github.com/matrix-org/dendrite/issues/2777 Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'roomserver/storage/shared')
-rw-r--r--roomserver/storage/shared/room_updater.go7
-rw-r--r--roomserver/storage/shared/storage.go23
2 files changed, 29 insertions, 1 deletions
diff --git a/roomserver/storage/shared/room_updater.go b/roomserver/storage/shared/room_updater.go
index 42c0c8f2..cc880a6c 100644
--- a/roomserver/storage/shared/room_updater.go
+++ b/roomserver/storage/shared/room_updater.go
@@ -5,8 +5,9 @@ import (
"database/sql"
"fmt"
- "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/gomatrixserverlib"
+
+ "github.com/matrix-org/dendrite/roomserver/types"
)
type RoomUpdater struct {
@@ -186,6 +187,10 @@ func (u *RoomUpdater) EventIDs(
return u.d.EventsTable.BulkSelectEventID(ctx, u.txn, eventNIDs)
}
+func (u *RoomUpdater) BulkSelectSnapshotsFromEventIDs(ctx context.Context, eventIDs []string) (map[types.StateSnapshotNID][]string, error) {
+ return u.d.EventsTable.BulkSelectSnapshotsFromEventIDs(ctx, u.txn, eventIDs)
+}
+
func (u *RoomUpdater) StateAtEventIDs(
ctx context.Context, eventIDs []string,
) ([]types.StateAtEvent, error) {
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index ed86280b..4455ec3b 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -469,6 +469,23 @@ func (d *Database) events(
eventNIDs = append(eventNIDs, nid)
}
}
+ // If we don't need to get any events from the database, short circuit now
+ if len(eventNIDs) == 0 {
+ results := make([]types.Event, 0, len(inputEventNIDs))
+ for _, nid := range inputEventNIDs {
+ event, ok := events[nid]
+ if !ok || event == nil {
+ return nil, fmt.Errorf("event %d missing", nid)
+ }
+ results = append(results, types.Event{
+ EventNID: nid,
+ Event: event,
+ })
+ }
+ if !redactionsArePermanent {
+ d.applyRedactions(results)
+ }
+ }
eventJSONs, err := d.EventJSONTable.BulkSelectEventJSON(ctx, txn, eventNIDs)
if err != nil {
return nil, err
@@ -534,6 +551,12 @@ func (d *Database) events(
return results, nil
}
+func (d *Database) BulkSelectSnapshotsFromEventIDs(
+ ctx context.Context, eventIDs []string,
+) (map[types.StateSnapshotNID][]string, error) {
+ return d.EventsTable.BulkSelectSnapshotsFromEventIDs(ctx, nil, eventIDs)
+}
+
func (d *Database) MembershipUpdater(
ctx context.Context, roomID, targetUserID string,
targetLocal bool, roomVersion gomatrixserverlib.RoomVersion,