aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/sqlite3/state_snapshot_table.go
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2021-08-04 17:08:17 +0100
committerGitHub <noreply@github.com>2021-08-04 17:08:17 +0100
commited04eed4411596a9ad83c322b89a7cbb49bf3b0f (patch)
tree5274f20b5235e31ca1ede3d606be0854721d36d0 /roomserver/storage/sqlite3/state_snapshot_table.go
parentda101469faab6667df83b859b782b65c84d8631e (diff)
Fix sqlite migration issues (#1960)
* Do not store 'null' in the database for empty JSON arrays This can cause issues, though it should be noted that the majority of the time this will marshal/unmarshal just fine, see https://play.golang.org/p/Doe2NZUgv7Q * 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. * Add state key check
Diffstat (limited to 'roomserver/storage/sqlite3/state_snapshot_table.go')
-rw-r--r--roomserver/storage/sqlite3/state_snapshot_table.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/roomserver/storage/sqlite3/state_snapshot_table.go b/roomserver/storage/sqlite3/state_snapshot_table.go
index ad623d65..040d99ae 100644
--- a/roomserver/storage/sqlite3/state_snapshot_table.go
+++ b/roomserver/storage/sqlite3/state_snapshot_table.go
@@ -87,6 +87,9 @@ func prepareStateSnapshotTable(db *sql.DB) (tables.StateSnapshot, error) {
func (s *stateSnapshotStatements) InsertState(
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, stateBlockNIDs types.StateBlockNIDs,
) (stateNID types.StateSnapshotNID, err error) {
+ if stateBlockNIDs == nil {
+ stateBlockNIDs = []types.StateBlockNID{} // zero slice to not store 'null' in the DB
+ }
stateBlockNIDs = stateBlockNIDs[:util.SortAndUnique(stateBlockNIDs)]
stateBlockNIDsJSON, err := json.Marshal(stateBlockNIDs)
if err != nil {