aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2021-08-04 17:48:23 +0100
committerGitHub <noreply@github.com>2021-08-04 17:48:23 +0100
commit4cc8b28b7f341c21a0bf7a261d6b49e8276e1e99 (patch)
tree7c73f6e9b4639fd3818f384beb9f20119ac3a9c5 /roomserver
parent7a9a2547b337acaa01a911a150871665799147a7 (diff)
Ensure all create events have a snapshot NID of 0 (#1961)
Fixes #1924 for postgres users, though the underlying cause of why they aren't 0 in the first place is unresolved.
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/storage/postgres/deltas/2021041615092700_state_blocks_refactor.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/roomserver/storage/postgres/deltas/2021041615092700_state_blocks_refactor.go b/roomserver/storage/postgres/deltas/2021041615092700_state_blocks_refactor.go
index 940a920e..6b72de51 100644
--- a/roomserver/storage/postgres/deltas/2021041615092700_state_blocks_refactor.go
+++ b/roomserver/storage/postgres/deltas/2021041615092700_state_blocks_refactor.go
@@ -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 {