-
Notifications
You must be signed in to change notification settings - Fork 1
β‘ Bolt: Optimize push_rules filtering logic #189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1074,23 +1074,24 @@ | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| original_count = len(hostnames) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Optimization 1: Deduplicate input list while preserving order | ||||||||||||||||||||||||||||||||||||||||
| # Optimization 2: Check directly against existing_rules to avoid O(N) copy. | ||||||||||||||||||||||||||||||||||||||||
| seen = set() | ||||||||||||||||||||||||||||||||||||||||
| # Optimization 1: Deduplicate input list while preserving order using dict.fromkeys() | ||||||||||||||||||||||||||||||||||||||||
| # This is significantly faster than using a 'seen' set in the loop for large lists. | ||||||||||||||||||||||||||||||||||||||||
| # It also naturally deduplicates invalid rules, preventing log spam. | ||||||||||||||||||||||||||||||||||||||||
| unique_hostnames = dict.fromkeys(hostnames) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| filtered_hostnames = [] | ||||||||||||||||||||||||||||||||||||||||
| skipped_unsafe = 0 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| for h in hostnames: | ||||||||||||||||||||||||||||||||||||||||
| for h in unique_hostnames: | ||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Variable name "h" doesn't conform to snake_case naming style Warning
Variable name "h" doesn't conform to snake_case naming style
|
||||||||||||||||||||||||||||||||||||||||
| if not is_valid_rule(h): | ||||||||||||||||||||||||||||||||||||||||
| log.warning( | ||||||||||||||||||||||||||||||||||||||||
| f"Skipping unsafe rule in {sanitize_for_log(folder_name)}: {sanitize_for_log(h)}" | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| skipped_unsafe += 1 | ||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if h not in existing_rules and h not in seen: | ||||||||||||||||||||||||||||||||||||||||
| if h not in existing_rules: | ||||||||||||||||||||||||||||||||||||||||
| filtered_hostnames.append(h) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1085
to
1094
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For improved readability, you can combine the two
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| seen.add(h) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if skipped_unsafe > 0: | ||||||||||||||||||||||||||||||||||||||||
| log.warning( | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Variable name "h" doesn't conform to snake_case naming style Warning