mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
bugfix: sqlite migration should handle create events as having no 'before' snapshot
The state snapshot for any given event in the roomserver represents the state _before_ the event. For the create event, this is nothing, so the state snapshot nid should be 0. In some cases this wasn't happening, resulting in a nice mix of possible options including: - A state snapshot without any state blocks `[]` or `null`. - A state snapshot with a single state block with a single event, the create event, causing a circular loop. This is incorrect as it represents the state before the event, not after.
This commit is contained in:
parent
17a7896614
commit
506499633b
|
|
@ -93,6 +93,20 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var newblocks types.StateBlockNIDs
|
var newblocks types.StateBlockNIDs
|
||||||
|
if len(blocks) == 0 {
|
||||||
|
// 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 state_snapshot_nid = $2`,
|
||||||
|
types.MRoomCreateNID, snapshot,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("resetting create events snapshots to 0 errored: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, block := range blocks {
|
for _, block := range blocks {
|
||||||
if err = func() error {
|
if err = func() error {
|
||||||
blockrows, berr := tx.Query(`SELECT event_nid FROM _roomserver_state_block WHERE state_block_nid = $1`, block)
|
blockrows, berr := tx.Query(`SELECT event_nid FROM _roomserver_state_block WHERE state_block_nid = $1`, block)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue