mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-09 07:03:10 -06:00
Review comments
This commit is contained in:
parent
f0d3d50dc0
commit
ab923987f7
|
|
@ -77,21 +77,25 @@ const bulkSelectStateBlockNIDsSQL = "" +
|
||||||
// helpers.CheckServerAllowedToSeeEvent function.
|
// helpers.CheckServerAllowedToSeeEvent function.
|
||||||
// TODO: There's a sequence scan here because of the hash join strategy, which is
|
// TODO: There's a sequence scan here because of the hash join strategy, which is
|
||||||
// probably O(n) on state key entries, so there must be a way to avoid that somehow.
|
// probably O(n) on state key entries, so there must be a way to avoid that somehow.
|
||||||
const bulkSelectStateForHistoryVisibilitySQL = "" +
|
// Event type NIDs are:
|
||||||
"SELECT event_nid FROM (" +
|
// - 5: m.room.member as per https://github.com/matrix-org/dendrite/blob/c7f7aec4d07d59120d37d5b16a900f6d608a75c4/roomserver/storage/postgres/event_types_table.go#L40
|
||||||
" SELECT event_nid, event_type_nid, event_state_key_nid FROM roomserver_events" +
|
// - 7: m.room.history_visibility as per https://github.com/matrix-org/dendrite/blob/c7f7aec4d07d59120d37d5b16a900f6d608a75c4/roomserver/storage/postgres/event_types_table.go#L42
|
||||||
" WHERE (event_type_nid = 5 OR event_type_nid = 7)" +
|
const bulkSelectStateForHistoryVisibilitySQL = `
|
||||||
" AND event_nid = ANY(" +
|
SELECT event_nid FROM (
|
||||||
" SELECT UNNEST(event_nids) FROM roomserver_state_block" +
|
SELECT event_nid, event_type_nid, event_state_key_nid FROM roomserver_events
|
||||||
" WHERE state_block_nid = ANY(" +
|
WHERE (event_type_nid = 5 OR event_type_nid = 7)
|
||||||
" SELECT UNNEST(state_block_nids) FROM roomserver_state_snapshots" +
|
AND event_nid = ANY(
|
||||||
" WHERE state_snapshot_nid = $1" +
|
SELECT UNNEST(event_nids) FROM roomserver_state_block
|
||||||
" )" +
|
WHERE state_block_nid = ANY(
|
||||||
" )" +
|
SELECT UNNEST(state_block_nids) FROM roomserver_state_snapshots
|
||||||
") AS roomserver_events" +
|
WHERE state_snapshot_nid = $1
|
||||||
" INNER JOIN roomserver_event_state_keys" +
|
)
|
||||||
" ON roomserver_events.event_state_key_nid = roomserver_event_state_keys.event_state_key_nid" +
|
)
|
||||||
" AND (event_type_nid = 7 OR event_state_key LIKE '%:' || $2);"
|
) AS roomserver_events
|
||||||
|
INNER JOIN roomserver_event_state_keys
|
||||||
|
ON roomserver_events.event_state_key_nid = roomserver_event_state_keys.event_state_key_nid
|
||||||
|
AND (event_type_nid = 7 OR event_state_key LIKE '%:' || $2);
|
||||||
|
`
|
||||||
|
|
||||||
type stateSnapshotStatements struct {
|
type stateSnapshotStatements struct {
|
||||||
insertStateStmt *sql.Stmt
|
insertStateStmt *sql.Stmt
|
||||||
|
|
@ -170,15 +174,12 @@ func (s *stateSnapshotStatements) BulkSelectStateForHistoryVisibility(
|
||||||
}
|
}
|
||||||
defer rows.Close() // nolint: errcheck
|
defer rows.Close() // nolint: errcheck
|
||||||
results := make([]types.EventNID, 0, 16)
|
results := make([]types.EventNID, 0, 16)
|
||||||
for i := 0; rows.Next(); i++ {
|
for rows.Next() {
|
||||||
var eventNID types.EventNID
|
var eventNID types.EventNID
|
||||||
if err = rows.Scan(&eventNID); err != nil {
|
if err = rows.Scan(&eventNID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
results = append(results, eventNID)
|
results = append(results, eventNID)
|
||||||
}
|
}
|
||||||
if err = rows.Err(); err != nil {
|
return results, rows.Err()
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return results, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,9 @@ type Rooms interface {
|
||||||
type StateSnapshot interface {
|
type StateSnapshot interface {
|
||||||
InsertState(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, stateBlockNIDs types.StateBlockNIDs) (stateNID types.StateSnapshotNID, err error)
|
InsertState(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, stateBlockNIDs types.StateBlockNIDs) (stateNID types.StateSnapshotNID, err error)
|
||||||
BulkSelectStateBlockNIDs(ctx context.Context, txn *sql.Tx, stateNIDs []types.StateSnapshotNID) ([]types.StateBlockNIDList, error)
|
BulkSelectStateBlockNIDs(ctx context.Context, txn *sql.Tx, stateNIDs []types.StateSnapshotNID) ([]types.StateBlockNIDList, error)
|
||||||
|
// BulkSelectStateForHistoryVisibility is a PostgreSQL-only optimisation for finding
|
||||||
|
// which users are in a room faster than having to load the entire room state. In the
|
||||||
|
// case of SQLite, this will return tables.OptimisationNotSupportedError.
|
||||||
BulkSelectStateForHistoryVisibility(ctx context.Context, txn *sql.Tx, stateSnapshotNID types.StateSnapshotNID, domain string) ([]types.EventNID, error)
|
BulkSelectStateForHistoryVisibility(ctx context.Context, txn *sql.Tx, stateSnapshotNID types.StateSnapshotNID, domain string) ([]types.EventNID, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue