-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
look up cross-signing keys from the DB in bulk #6486
Conversation
to improve performance of looking up 500 users' keys. Also improve some docstrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It'd be good to also add a cache here, as e.g. if a room enables encryption then we'll get N users asking for the keys of the other N users, so adding a cache should help a lot. (c.f. @cachedList
)
Ah, I forgot to do this. So the difficulty here is that the I think that it'll end up being a big change, so I'll take it out of review until it's done. |
I've split out the first query into a separate function, and set it up to take a list of key types. However, I'm running into some issues adding the caching.
|
Yeah, I'm afraid they will need to be in separate transactions (and you can then cache both transactions). I don't think that'll cause too much overhead as its just one extra query per request, rather than an extra query per queried user?
I think including the key type is fine, the default cache sizes aren't that big so it won't use that much extra memory by default. You can then use The other option is to have the query return all keys for a user, filter the keys after the cache, and then invalidate all keys for a user if one of them changes. It's not perfect, but probably good enough. |
Tests were working fine until I merged in Anyways, aside from that, should be ready for review now. |
Looks like it might be exploding due to a leaked log context, somewhere |
Tests pass now. Should be good now. There is a bit of ugliness, though, in that the |
list_name="user_ids", | ||
num_args=1, | ||
) | ||
def _get_bare_e2e_cross_signing_keys_bulk(self, user_ids: list) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _get_bare_e2e_cross_signing_keys_bulk(self, user_ids: list) -> dict: | |
def _get_bare_e2e_cross_signing_keys_bulk(self, user_ids: List[str]) -> Dict[str, Dict[str, dict]]: |
(You might need to import from typing
)
the signatures for the calling user need to be fetched. | ||
|
||
Args: | ||
txn (twisted.enterprise.adbapi.Connection): db connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
txn (twisted.enterprise.adbapi.Connection): db connection |
@@ -271,7 +271,7 @@ def __init__( | |||
else: | |||
self.function_to_call = orig | |||
|
|||
arg_spec = inspect.getargspec(orig) | |||
arg_spec = inspect.getfullargspec(orig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ooi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I was going to add a comment explaining it. It's because _get_bare_e2e_cross_signing_keys_bulk
has type annotations, so getargspec
doesn't work on it, and it suggests to use getfullargspec
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaaaaah, cool
* commit 'cb2db1799': look up cross-signing keys from the DB in bulk (#6486)
to improve performance of looking up 500 users' keys.
Also improve some docstrings.