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 query methods for data source handling #9

Merged
merged 12 commits into from
May 22, 2024

Conversation

maxachis
Copy link

@maxachis maxachis commented May 12, 2024

Fixes

Description

  • Replaces god function antipatterns in relevant middleware functions with direct calls to the relevant functions in Resources
  • Where necessary, logic from god functions have been migrated into either the relevant functions or the Resources functions
  • Previous god functions have been deleted

Testing

  • Run test_data_source_queries, test_archives_queries to confirm continued operation of functionality.

Performance

  • Performance impact minimal; additional tests added

Docs

  • Not applicable.

maxachis added 8 commits May 11, 2024 20:02
The code has been refactored to individual query methods for clear data handling and improve readability. The 'data_sources_query' method in 'DataSources.py' which was previously handling all query types is replaced with specific, self-explanatory query methods such as 'get_approved_data_sources', 'needs_identification_data_sources' and 'get_data_sources_for_map'. This also leads to the introduction of 'convert_data_source_matches' in 'data_source_queries.py' file for better format conversion.
The archives_put_query method has been removed from the archives_queries.py and its functionality has been split into direct calls to the appropriate methods, archives_put_broken_as_of_results or archives_put_last_cached_results. This change simplifies the code and makes it more legible by clearly specifying the function being used in each situation. The refactoring also involves adjustments in the Archives.py resource to accommodate these changes.
Updated data access in various tests, which replaced indexed access with direct attribute access. Added a test 'convert_data_source_matches' to validate the conversion of data source matches to dictionaries. Removed unused test method 'test_data_sources_query' as it was no longer relevant. These adjustments enhance readability and maintainability of test codes.
The function 'convert_data_source_matches' now has type hints and a descriptive docstring. This change provides clarity on what the function expects as parameters and what it returns. Improved documentation aids in understanding the code and enhances maintainability.
…_281_middleware_god_function_actual

# Conflicts:
#	resources/Archives.py
#	resources/DataSources.py
@maxachis maxachis changed the base branch from main to dev May 22, 2024 20:30
@maxachis maxachis marked this pull request as ready for review May 22, 2024 20:36
maxachis added 2 commits May 22, 2024 16:38
This commit replaces the broken data_sources_query function calls in the SearchTokens module with properly defined functions. This includes using the new get_approved_data_sources function for fetching approved data sources and get_data_sources_for_map for getting data sources specific to maps.
@maxachis maxachis merged commit 82274c9 into dev May 22, 2024
9 checks passed
@maxachis maxachis deleted the mc_issue_181_middleware_god_function_actual branch May 22, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant