summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-05-31 19:08:31 +0100
committerErik Johnston <erik@matrix.org>2018-05-31 19:08:31 +0100
commit8384b1f3aa6ffaeb5c5bdfc66d704e4763bb6321 (patch)
treec0d3d9555c1ea7fff98e43205671483ad8b5b585
parentUse fractions (diff)
downloadsynapse-8384b1f3aa6ffaeb5c5bdfc66d704e4763bb6321.tar.xz
Fixup
-rw-r--r--synapse/storage/schema/delta/49/event_chunks.py16
1 files 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