Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add receipts event stream ordering #13703

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13703.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add & populate `event_stream_ordering` column on receipts table for future optimisation of push action processing. Contributed by Nick @ Beeper (@fizzadar).
14 changes: 9 additions & 5 deletions synapse/storage/databases/main/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,14 @@ def _insert_linearized_receipt_txn(
self._receipts_stream_cache.entity_has_changed, room_id, stream_id
)

upsert_values: Dict[str, Any] = {
"stream_id": stream_id,
"event_id": event_id,
"data": json_encoder.encode(data),
}
if stream_ordering is not None:
upsert_values["event_stream_ordering"] = stream_ordering
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to pull this out? If stream_ordering is None then it will get inserted as NULL, which is what we'd get anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was the upsert would leave the old value in place if this wasn't set, but I think this is a rare edge case and it's better to have consistency between the columns, so will inline it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaah, OK yeah that is a valid reason, though I do think its better to have consistency (otherwise my poor brain will get very confused if they ever got out of sync)


self.db_pool.simple_upsert_txn(
txn,
table="receipts_linearized",
Expand All @@ -672,11 +680,7 @@ def _insert_linearized_receipt_txn(
"receipt_type": receipt_type,
"user_id": user_id,
},
values={
"stream_id": stream_id,
"event_id": event_id,
"data": json_encoder.encode(data),
},
values=upsert_values,
# receipts_linearized has a unique constraint on
# (user_id, room_id, receipt_type), so no need to lock
lock=False,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright 2022 Beeper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

ALTER TABLE receipts_linearized ADD COLUMN event_stream_ordering integer;
Fizzadar marked this conversation as resolved.
Show resolved Hide resolved