Skip to content

Commit 8623129

Browse files
committed
style(api): drop decorative banners and tidy comments in scan hot loop
1 parent 1ad8863 commit 8623129

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

api/src/backend/tasks/jobs/scan.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -572,14 +572,12 @@ def _process_finding_micro_batch(
572572
if uid not in last_status_cache:
573573
last_status_cache[uid] = data
574574

575-
# ============================================================
576-
# All DB writes for this micro-batch run inside ONE rls_transaction
577-
# (with deadlock-retry at micro-batch granularity instead of per-finding).
578-
# ============================================================
575+
# All DB writes for this micro-batch run inside ONE rls_transaction,
576+
# with deadlock-retry at micro-batch granularity instead of per-finding.
579577
for attempt in range(CELERY_DEADLOCK_ATTEMPTS):
580578
try:
581579
with rls_transaction(tenant_id):
582-
# ---- 1) Pre-resolve Resources in bulk ----
580+
# 1) Pre-resolve Resources in bulk
583581
# Collect all uids referenced by this batch that are not in cache yet.
584582
# NOTE: we intentionally include empty-string uids here. The SDK
585583
# explicitly emits findings with `resource_uid=""` for some flows
@@ -647,7 +645,7 @@ def _process_finding_micro_batch(
647645
resource_cache[uid] = r
648646
resource_failed_findings_cache.setdefault(uid, 0)
649647

650-
# ---- 2) Pre-resolve ResourceTags in bulk ----
648+
# 2) Pre-resolve ResourceTags in bulk
651649
batch_tag_kv: set[tuple[str, str]] = set()
652650
for f in non_null_findings:
653651
for k, v in f.resource_tags.items():
@@ -686,7 +684,7 @@ def _process_finding_micro_batch(
686684
)
687685
tag_cache.update(existing_tags)
688686

689-
# ---- 3) Per-finding in-memory processing ----
687+
# 3) Per-finding in-memory processing
690688
for finding in non_null_findings:
691689
resource_uid = finding.resource_uid
692690
resource_instance = resource_cache.get(resource_uid)
@@ -856,7 +854,7 @@ def _process_finding_micro_batch(
856854
group_resources_cache=group_resources_cache,
857855
)
858856

859-
# ---- 4) Bulk create ResourceTagMappings ----
857+
# 4) Bulk create ResourceTagMappings
860858
# Replaces the original per-resource `upsert_or_delete_tags`
861859
# (which did one `update_or_create` + SELECT FOR UPDATE per mapping).
862860
if tag_mappings_to_create:
@@ -878,13 +876,13 @@ def _process_finding_micro_batch(
878876
if uid is not None:
879877
resources_with_new_tag_mappings.add(uid)
880878

881-
# ---- 5) Bulk create Findings ----
879+
# 5) Bulk create Findings
882880
if findings_to_create:
883881
Finding.objects.bulk_create(
884882
findings_to_create, batch_size=SCAN_DB_BATCH_SIZE
885883
)
886884

887-
# ---- 6) Bulk create ResourceFindingMapping rows ----
885+
# 6) Bulk create ResourceFindingMapping rows
888886
mappings_to_create = [
889887
ResourceFindingMapping(
890888
tenant_id=tenant_id,
@@ -908,14 +906,7 @@ def _process_finding_micro_batch(
908906
f"inserted {inserted}. Rolling back micro-batch."
909907
)
910908

911-
# ---- 7) (eliminado) Bulk update finding denormalized arrays
912-
# Antes habia un Finding.bulk_update sobre resource_regions/
913-
# resource_services/resource_types tras el INSERT. Ahora esos
914-
# arrays se poblan directamente al construir el Finding
915-
# (ver paso 3), eliminando el UPDATE CASE WHEN posterior.
916-
# Saves ~14ms/call x 6 calls = ~86ms per micro-batch.
917-
918-
# ---- 8) Bulk update Resources ----
909+
# 7) Bulk update Resources
919910
# Union of:
920911
# - resources whose fields changed (dirty_resources)
921912
# - resources that got new tag mappings (need updated_at bump,

0 commit comments

Comments
 (0)