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

Improve drift detection perf, tests, and add some typehints #1186

Merged
merged 3 commits into from
Jun 15, 2023

Conversation

achantavy
Copy link
Contributor

Uses a set membership check instead of iterating through each item in the list of results to detect drift.

Adds unit test to ensure order of results does not matter in the drift detection check.

Also adds some typehints.

session: neo4j.Session,
query_directory: str,
state_serializer: StateSchema,
storage,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not adding a typehint here because it seems like we're doing this ducktyping thing where we expect the storage object to have a write() function and other methods but I don't want to necessarily restrict it to just the existing storage.FileSystem object.

@@ -92,10 +96,12 @@ def compare_states(start_state, end_state):
:return: list of tuples of differences between states in the form (dictionary, State object)
"""
differences = []
# Use set for faster membership check
start_state_results = {tuple(res) for res in start_state.results}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main change of this PR. Spend more memory for faster lookup.

continue
drift = []
drift: List[Union[str, List[str]]] = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not a fan of how the list can have more than one type (and mypy isn't particularly happy about this either) but I don't want to break anything

@achantavy achantavy merged commit da243af into master Jun 15, 2023
@achantavy achantavy deleted the ddimprovements branch June 15, 2023 15:53
chandanchowdhury pushed a commit to juju4/cartography that referenced this pull request Jun 26, 2024
Uses a set membership check instead of iterating through each item in
the list of results to detect drift.

Adds unit test to ensure order of results does not matter in the drift
detection check.

Also adds some typehints.
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