Conversation
| async def _claim_e2e_fallback_keys_simple( | ||
| self, | ||
| query_list: Iterable[Tuple[str, str, str, bool]], | ||
| ) -> Dict[str, Dict[str, Dict[str, JsonDict]]]: |
There was a problem hiding this comment.
Ouch -- this was doing 2 queries for each item in the input list.
| WITH claims(user_id, device_id, algorithm, mark_as_used) AS ( | ||
| VALUES ? | ||
| ) | ||
| UPDATE e2e_fallback_keys_json k | ||
| SET used = used OR mark_as_used | ||
| FROM claims | ||
| WHERE (k.user_id, k.device_id, k.algorithm) = (claims.user_id, claims.device_id, claims.algorithm) | ||
| RETURNING k.user_id, k.device_id, k.algorithm, k.key_id, k.key_json; |
There was a problem hiding this comment.
The form WITH ... UPDATE ... is non-standard, according to https://www.postgresql.org/docs/11/sql-update.html#id-1.9.3.182.10:
This command conforms to the SQL standard, except that the FROM and RETURNING clauses are PostgreSQL extensions, as is the ability to use WITH with UPDATE.
clokep
left a comment
There was a problem hiding this comment.
Seems reasonable! Any idea if this is decently unit tests or not?
synapse/tests/handlers/test_e2e_keys.py Lines 177 to 395 in 9ec3da0
it doesn't seem to test requesting more than one key at a time though. It might be prudent to add something for that. |
|
@clokep I've written a short test of the bulk-fetching behaviour to keep me honest. Mind taking one more (last?) look? |
|
LGTM! Thank for adding. |
This is the second performance change as suggested by from Rich in #16554. The first was #16565.
Testing that the query is legit
Commitwise reviewable. Completely untested outside of the practice query and CI.