Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Ensure all create events have a snapshot NID of 0 (#1961)
Browse files Browse the repository at this point in the history
Fixes #1924 for postgres users, though the underlying cause of why
they aren't 0 in the first place is unresolved.
  • Loading branch information
kegsay authored Aug 4, 2021
1 parent 7a9a254 commit 4cc8b28
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
return fmt.Errorf("tx.Exec (create snapshots table): %w", err)
}
logrus.Warn("New tables created...")
// some m.room.create events have a state snapshot but no state blocks at all which makes
// sense as there is no state before creation. The correct form should be to give the event
// in question a state snapshot NID of 0 to indicate 'no snapshot'.
// If we don't do this, we'll fail the assertions later on which try to ensure we didn't forget
// any snapshots.
_, err = tx.Exec(
`UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE event_type_nid = $1 AND event_state_key_nid = $2`,
types.MRoomCreateNID, types.EmptyStateKeyNID,
)
if err != nil {
return fmt.Errorf("resetting create events snapshots to 0 errored: %s", err)
}

batchsize := 100
for batchoffset := 0; batchoffset < snapshotcount; batchoffset += batchsize {
Expand Down

0 comments on commit 4cc8b28

Please sign in to comment.