0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 16:03:51 +01:00

Incorporate review

This commit is contained in:
Brendan Abolivier 2019-11-07 15:25:27 +00:00
parent 24a214bd1b
commit bb78276bdc
No known key found for this signature in database
GPG key ID: 1E015C145F1916CD

View file

@ -525,43 +525,38 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore):
(last_event_id, batch_size), (last_event_id, batch_size),
) )
rows = self.cursor_to_dict(txn) nbrows = 0
if not rows: for (event_id, event_json) in txn:
return True, 0
for row in rows:
event_id = row["event_id"]
event_json = json.loads(row["json"])
self._simple_insert_many_txn( self._simple_insert_many_txn(
txn=txn, txn=txn,
table="event_labels", table="event_labels",
values=[ values=[
{ {
"event_id": event_id, "event_id": event_id,
"label": label, "label": str(label),
"room_id": event_json["room_id"], "room_id": event_json["room_id"],
"topological_ordering": event_json["depth"], "topological_ordering": event_json["depth"],
} }
for label in event_json["content"].get( for label in event_json["content"].get(
EventContentFields.LABELS, [] EventContentFields.LABELS, []
) )
if label is not None
], ],
) )
nbrows += 1
self._background_update_progress_txn( self._background_update_progress_txn(
txn, "event_store_labels", {"last_event_id": event_id} txn, "event_store_labels", {"last_event_id": event_id}
) )
# We want to return true (to end the background update) only when return nbrows
# the query returned with less rows than we asked for.
return len(rows) != batch_size, len(rows)
end, num_rows = yield self.runInteraction( num_rows = yield self.runInteraction(
desc="event_store_labels", func=_event_store_labels_txn desc="event_store_labels", func=_event_store_labels_txn
) )
if end: if not num_rows:
yield self._end_background_update("event_store_labels") yield self._end_background_update("event_store_labels")
return num_rows return num_rows