-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
techdebt(RHINENG-12028): serialize_host refactoring proposal
Issues identified: Repetitive staleness calculation: * The stale_timestamp, stale_warning_timestamp, and culled_timestamp assignments are redundant for edge and conventional hosts. * We should extract this logic into a helper function. Field processing in a long if-else chain: * The current approach of checking each field separately makes it harder to read. * Using a dictionary comprehension may make it cleaner. Unused arguments (additional_fields defaulted to tuple()): * We should use None as a default, and convert it to a tuple inside the function. Better separation of concerns: * Extract helper functions to make the serialize_host function more modular. Improvements Proposal: Encapsulating the staleness calculation: * Extracting the calculation into a get_staleness_timestamps() helper function to avoid duplicate logic. Reducing repetitive "if" Checks: * By using a dictionary field_mapping to map field names to their corresponding serialization logic. * By doing this, we eliminate long "if" chains, making it cleaner and easier to modify. Optimizing System Profile management: * By using a dictionary comprehension to filter system_profile_facts efficiently. Improving readability and Maintainability: * By bringing a better logical separation of concerns. * By bringing an easier way to extend the host data (we just need to modify the field_mapping and add/remove fields). Signed-off-by: Gaël Chamoulaud <[email protected]> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
- Loading branch information
Showing
1 changed file
with
73 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters