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

Enable cancellation of GET /members and GET /state requests #12708

Merged
merged 6 commits into from
May 11, 2022
Merged
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ class SomeServlet(RestServlet):
async def on_GET(self, request: SynapseRequest) -> ...:
...
"""
if method.__name__ not in _cancellable_method_names:
if method.__name__ not in _cancellable_method_names and not any(
method.__name__.startswith(name) for name in _cancellable_method_names
):
Copy link
Contributor

Choose a reason for hiding this comment

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

For any string x, x.startswith(x). So I think this could be

    if not any(
        method.__name__.startswith(prefix) for prefix in _cancellable_method_names
    ):

but having written that out, I'm not sure if it's clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: this is used later when we decorate on_GET_no_state_key.

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 string-in-set test is much faster (O(len(str)) and would succeed for almost every method we would use the decorator on. The prefix test is a lot slower (O(n len(str))), since it has to trawl through the list, and only applies to on_GET_no_state_key.

Not that any of this matters, since it's all startup cost.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming name to prefix in the generator is a good idea though!

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair. Glad you agree on prefix; I was a bit confused by all the names flying around.

raise ValueError(
"@cancellable decorator can only be applied to servlet methods."
)
Expand Down