Skip to content

Commit

Permalink
Pass room ID to new query
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Apr 24, 2023
1 parent 8324f6e commit 6c9aa09
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion state/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (a *Accumulator) Initialise(roomID string, state []json.RawMessage) (Initia
eventIDToRawEvent[eventID.Str] = state[i]
eventIDs[i] = eventID.Str
}
unknownEventIDs, err := a.eventsTable.SelectUnknownEventIDs(txn, eventIDs)
unknownEventIDs, err := a.eventsTable.SelectUnknownEventIDs(txn, roomID, eventIDs)
if err != nil {
return fmt.Errorf("error determing which event IDs are unknown: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions state/event_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,18 @@ func (t *EventTable) SelectStrippedEventsByIDs(txn *sqlx.Tx, verifyAll bool, ids

// SelectUnknownEventIDs accepts a list of event IDs and returns the subset of those which are not known to the DB.
// It MUST be called within a transaction, or else will panic.
func (t *EventTable) SelectUnknownEventIDs(txn *sqlx.Tx, maybeUnknownEventIDs []string) (map[string]struct{}, error) {
func (t *EventTable) SelectUnknownEventIDs(txn *sqlx.Tx, roomID string, maybeUnknownEventIDs []string) (map[string]struct{}, error) {
// Note: in practice, the order of rows returned matches the order of rows of
// array entries. But I don't think that's guaranteed. Return an (unordered) set
// out of paranoia.
queryStr := `
WITH maybe_unknown_events(event_id) AS (SELECT unnest($1::text[]))
WITH maybe_unknown_events(event_id) AS (SELECT unnest($2::text[]))
SELECT event_id
FROM maybe_unknown_events LEFT JOIN syncv3_events USING(event_id)
WHERE event_nid IS NULL;`
WHERE room_id = $1 AND event_nid IS NULL;`

var unknownEventIDs []string
if err := txn.Select(&unknownEventIDs, queryStr, pq.StringArray(maybeUnknownEventIDs)); err != nil {
if err := txn.Select(&unknownEventIDs, queryStr, roomID, pq.StringArray(maybeUnknownEventIDs)); err != nil {
return nil, err
}
unknownMap := make(map[string]struct{}, len(unknownEventIDs))
Expand Down
6 changes: 3 additions & 3 deletions state/event_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,10 @@ func TestEventTableSelectUnknownEventIDs(t *testing.T) {
t.Fatalf("failed to start txn: %s", err)
}
defer txn.Rollback()
const roomID = "!1:localhost"
const roomID = "!1TestEventTableSelectUnknownEventIDs:localhost"

// Note: there shouldn't be any other events with these IDs inserted before this
// transaction. $A and $B seem to be inserted and commit in TestEventTablePrevBatch.
// transaction. "$A" and "$B" seem to be inserted and commit in TestEventTablePrevBatch.
const eventID1 = "$A-SelectUnknownEventIDs"
const eventID2 = "$B-SelectUnknownEventIDs"

Expand Down Expand Up @@ -930,7 +930,7 @@ func TestEventTableSelectUnknownEventIDs(t *testing.T) {
// event IDs are unknown.
shouldBeUnknownIDs := []string{"$C-SelectUnknownEventIDs", "$D-SelectUnknownEventIDs"}
stateBlockIDs := append(shouldBeUnknownIDs, eventID1)
unknownIDs, err := table.SelectUnknownEventIDs(txn, stateBlockIDs)
unknownIDs, err := table.SelectUnknownEventIDs(txn, roomID, stateBlockIDs)
t.Logf("unknownIDs=%v", unknownIDs)
if err != nil {
t.Fatalf("failed to select unknown state events: %s", err)
Expand Down

0 comments on commit 6c9aa09

Please sign in to comment.