From 8384b1f3aa6ffaeb5c5bdfc66d704e4763bb6321 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 31 May 2018 19:08:31 +0100 Subject: [PATCH] Fixup --- synapse/storage/schema/delta/49/event_chunks.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/synapse/storage/schema/delta/49/event_chunks.py b/synapse/storage/schema/delta/49/event_chunks.py index 12c8cd9e3f..e4eceedb3a 100644 --- a/synapse/storage/schema/delta/49/event_chunks.py +++ b/synapse/storage/schema/delta/49/event_chunks.py @@ -60,7 +60,7 @@ CREATE TABLE chunk_linearized ( CREATE UNIQUE INDEX chunk_linearized_id ON chunk_linearized (chunk_id); CREATE UNIQUE INDEX chunk_linearized_next_id ON chunk_linearized ( - next_chunk_id, room_id, + next_chunk_id, room_id ); CREATE TABLE chunk_linearized_first ( @@ -93,6 +93,7 @@ def run_create(cur, database_engine, *args, **kwargs): next_chunk_id = 1 room_to_next_order = {} + prev_chunks_by_room = {} for row in rows: chunk_id = next_chunk_id @@ -111,6 +112,8 @@ def run_create(cur, database_engine, *args, **kwargs): ordering = room_to_next_order.get(room_id, 1) room_to_next_order[room_id] = ordering + 1 + prev_chunks = prev_chunks_by_room.setdefault(room_id, []) + SQLBaseStore._simple_insert_txn( txn, table="chunk_linearized", @@ -122,7 +125,14 @@ def run_create(cur, database_engine, *args, **kwargs): }, ) - if ordering == 1: + if prev_chunks: + SQLBaseStore._simple_update_one_txn( + txn, + table="chunk_linearized", + keyvalues={"chunk_id": prev_chunks[-1]}, + updatevalues={"next_chunk_id": chunk_id}, + ) + else: SQLBaseStore._simple_insert_txn( txn, table="chunk_linearized_first", @@ -132,6 +142,8 @@ def run_create(cur, database_engine, *args, **kwargs): }, ) + prev_chunks.append(chunk_id) + def run_upgrade(*args, **kwargs): pass