Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a persistent session when making requests #352

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

andrew-uoa
Copy link
Collaborator

@andrew-uoa andrew-uoa commented Dec 18, 2023

Change the MyTardis client class (MyTardisRESTFactory) so that it creates a requests Session object on construction, and uses this session for all of its requests. This speeds up requests, as otherwise, usng the default requests.request(...), a new HTTP connection is created every time a request is made.

It's worth noting that the session object is not just for persisting the HTTP connection; it also persists cookies etc. It seems unlikely this would cause problems, and I haven't seen any.

Documentation for the Session object can be found here:
https://requests.readthedocs.io/en/latest/user/advanced/

@andrew-uoa andrew-uoa force-pushed the persistent_request_session branch from 6d3e9da to 02b714c Compare December 19, 2023 04:36
@andrew-uoa andrew-uoa marked this pull request as ready for review December 19, 2023 04:45
@andrew-uoa andrew-uoa force-pushed the persistent_request_session branch 3 times, most recently from e49441f to d79fe58 Compare December 20, 2023 23:06
@andrew-uoa andrew-uoa force-pushed the persistent_request_session branch from d79fe58 to a42ca8b Compare December 21, 2023 01:37
@andrew-uoa andrew-uoa merged commit 4cfc4ad into main Jan 10, 2024
3 checks passed
@andrew-uoa andrew-uoa deleted the persistent_request_session branch January 10, 2024 02:00
JLoveUOA pushed a commit that referenced this pull request Jan 24, 2024
* Use a persistent session when making requests, to speed them up by recycling the HTTP connection

* Move session initialization to the constructor, and remove a redundant conditional branch

* Fix the test mock patching to reflect changes to which request method we're calling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant