Skip to content

Commit a46bf5a

Browse files
perf(tags): short-circuit flush_for_product when inheritance is disabled
`tag_inheritance.flush_for_product` is called unconditionally from the importer's `process_scan` (and reimporter equivalent). When tag inheritance is disabled (neither the system-wide flag nor the per-product flag is set) the previous implementation still walked every child queryset to compute the (empty) diff, adding ~9 queries per scan. Tests in `unittests/test_importers_performance.py` pin importer query counts in scenarios where inheritance is off. The Stage 2 commit's flush call shifted those baselines up by 9 across 10 test cases. Add an early-exit so the importer perf tests stay green and no behavior change ships under the inheritance-off configuration.
1 parent e4193ae commit a46bf5a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

dojo/tag_inheritance.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ def flush_for_product(product) -> None:
6767
``propagate_tags_on_product_sync``, which uses the Phase A bulk-diff
6868
helpers to sync `inherited_tags` and `tags` across all children in O(1)
6969
queries per (model x tag) instead of O(N) rows.
70+
71+
Short-circuits when tag inheritance is disabled (neither the system-wide
72+
flag nor the per-product flag is set) so callers (e.g. importers) can
73+
invoke this unconditionally without paying for it.
7074
"""
71-
# Local import to avoid circulars at module import time.
75+
# Local imports to avoid circulars at module import time.
7276
from dojo.product.helpers import propagate_tags_on_product_sync # noqa: PLC0415
77+
from dojo.utils import get_system_setting # noqa: PLC0415
78+
if not getattr(product, "enable_product_tag_inheritance", False) and not get_system_setting("enable_product_tag_inheritance"):
79+
return
7380
propagate_tags_on_product_sync(product)

0 commit comments

Comments
 (0)