This commit is contained in:
Erik Johnston 2018-05-31 19:08:31 +01:00
parent 1e666c7b72
commit 8384b1f3aa
1 changed files with 14 additions and 2 deletions

View File

@ -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