Skip to content

Add bug_map as a cached property for LandingsRiskReportGenerator#6268

Open
Karthikvenugopal wants to merge 1 commit into
mozilla:masterfrom
Karthikvenugopal:bug_map-cached-property
Open

Add bug_map as a cached property for LandingsRiskReportGenerator#6268
Karthikvenugopal wants to merge 1 commit into
mozilla:masterfrom
Karthikvenugopal:bug_map-cached-property

Conversation

@Karthikvenugopal

Copy link
Copy Markdown

Summary

Implements the follow-up from #5053: bug_map is now a @cached_property on
LandingsRiskReportGenerator instead of a local dict in go() passed as an
explicit argument to every method that needs it.

Changes

  • Add from functools import cached_property.
  • Add a bug_map cached property reproducing the existing filtering (keep bugs
    we are interested in, bugs blocked by other bugs, and bugs that caused
    regressions).
  • Promote the locals the property depends on (bugs, test_info_bugs,
    meta_bugs) to instance attributes set in go() before bug_map is first
    accessed.
  • Drop the bug_map parameter from get_blocking_of,
    generate_landings_by_date, generate_component_connections, and
    generate_component_test_stats, and update their bodies and the call sites in
    go() to use self.bug_map.

Why the dependencies had to move too

bug_map is filtered against bugs_set, which is derived from the bugs,
test_info_bugs, and meta_bugs locals computed earlier in go(). A
cached_property only receives self, so those inputs had to live on the
instance for the property to rebuild the same set. They are assigned in go()
before any consumer touches self.bug_map.

Notes

  • No method mutates bug_map, so sharing a single cached dict across consumers
    is safe.
  • The generator is instantiated once and go() runs once per process, so
    keeping these values on the instance does not change the effective memory
    lifetime.

Testing

  • pre-commit run --all-files passes (ruff, ruff-format, mypy, codespell, etc.).
  • No existing test exercises this script.

Fixes #5053

bug_map was built as a local dict inside go() and threaded through
get_blocking_of, generate_landings_by_date, generate_component_connections,
and generate_component_test_stats as an explicit parameter. Turn it into a
@cached_property so it no longer has to be passed around.

Because bug_map is filtered against bugs_set, which is derived from the bugs,
test_info_bugs, and meta_bugs locals computed in go(), those locals are now
promoted to instance attributes (self.bugs, self.test_info_bugs,
self.meta_bugs), set in go() before bug_map is first accessed. The property
can then rebuild bugs_set and compute bug_map from self alone, preserving the
existing filtering (bugs we are interested in, bugs blocked by other bugs,
and bugs that caused regressions).

Fixes mozilla#5053
@Karthikvenugopal

Copy link
Copy Markdown
Author

Hi @suhaibmujahid, this PR implements the @cached_property follow-up you suggested in #5053. Since bug_map is filtered against bugs_set (derived from the bugs, test_info_bugs, and meta_bugs locals in go()), I promoted those three to instance attributes so the property can build it from self alone; the four methods that previously took bug_map as a parameter now read self.bug_map. pre-commit run --all-files passes. Would appreciate your review when you get a chance. Thanks!

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.

Add bug_map as a cached property for LandingsRiskReportGenerator

1 participant