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

Refactor search to get rid of dependency on static api_client instance #468

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

jacksonj04
Copy link
Collaborator

@jacksonj04 jacksonj04 commented Nov 27, 2023

Searching currently relies on the static instance of api_client which is initialised at Client load-time to interface with the database and retrieve metadata.

This instance is deprecated and due for removal, so we need to fix this behaviour. Search should only ever use the Client instance it was called with, so we need to either inject the dependency down or refactor the behaviour so it can directly access the Client.

As part of this, we move factory methods out of SearchResultMetadata and SearchResult, which provides a cleaner separation of concerns and reduces the depth to which we need to make changes to account for removing api_client.

There should be no functional changes as a result of this PR, and it should be non-breaking for EUI and PUI.

@jacksonj04 jacksonj04 force-pushed the chore/refactor-apiclient-out-of-search branch from 18b4edc to d6456f9 Compare November 27, 2023 16:03
Previously, `SearchResultMetadata` had a static `create_from_uri` method
which was being called by `SearchResult`, which then ultimately
initialised an instance of `SearchResultMetadata`.

However, this is the _only_ place where this method was being called
from. This means we can push this method upwards into `SearchResult` and
avoid the need for a class acting as its own factory.
This method was making `SearchResponse` its own factory, but was only
ever being used to perform XML parsing. We can move this back up the
stack to clarify what is going on here.
@jacksonj04 jacksonj04 force-pushed the chore/refactor-apiclient-out-of-search branch from 93997f7 to b9a08ee Compare November 28, 2023 17:22
Search, specifically metadata handling, was relying on the static
instance of api_client which was initialised as part of loading this API
library. This instance is due to be deprecated, which means that instead
the dynamic instance which is initialised by the calling code must be
passed back down the stack.
@jacksonj04 jacksonj04 changed the title Refactor search to get rid of dependency on static api_client instance Refactor search to get rid of dependency on static api_client instance, and then remove it Nov 28, 2023
@jacksonj04 jacksonj04 marked this pull request as ready for review November 28, 2023 22:41
@jacksonj04 jacksonj04 force-pushed the chore/refactor-apiclient-out-of-search branch from 00846de to 077b646 Compare November 28, 2023 22:42
@jacksonj04 jacksonj04 changed the title Refactor search to get rid of dependency on static api_client instance, and then remove it Refactor search to get rid of dependency on static api_client instance Nov 28, 2023
Copy link
Contributor

@timcowlishaw timcowlishaw left a comment

Choose a reason for hiding this comment

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

Looks like a great improvement to me, just one comment where we could perhaps refactor further! Not a blocker though.

@jacksonj04 jacksonj04 merged commit 2bcb0b1 into main Nov 29, 2023
17 checks passed
@jacksonj04 jacksonj04 deleted the chore/refactor-apiclient-out-of-search branch November 29, 2023 10:37
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.

2 participants