Skip to content

perf(migration): batch endpoint tags and restore inheritance#15311

Open
AKSHATSPAR wants to merge 2 commits into
DefectDojo:bugfixfrom
AKSHATSPAR:fix/15124-bulk-migration-tags
Open

perf(migration): batch endpoint tags and restore inheritance#15311
AKSHATSPAR wants to merge 2 commits into
DefectDojo:bugfixfrom
AKSHATSPAR:fix/15124-bulk-migration-tags

Conversation

@AKSHATSPAR

@AKSHATSPAR AKSHATSPAR commented Jul 22, 2026

Copy link
Copy Markdown

⚠️ Pre-Approval check ⚠️

This is a bug fix for #15124, not a new enhancement.

Description

The reporter's completed migration, whose progress output initially listed 65,194 Endpoints, attributed 115,317.36 seconds (99.8% of its measured phase time) to tags and required several restarts. The command copies tags separately for each tagged Endpoint; in a controlled rerun of the exact PR base, those writes also increased Tagulous counters without creating new relationships.

This PR:

Tests

Added focused coverage for full and partial batches, duplicate Locations, clean reruns, inherited tags, atomic rollback, and per-Endpoint recovery.

Local validation: 3 migration tests passed, 29 bulk-tag tests passed, and 39 inheritance tests completed (37 passed, 2 skipped). Django system and migration checks and Ruff also passed.

Controlled comparison

I compared the exact PR base (22e2519) and patch in two fresh databases inside the same PostgreSQL 18.4 container. The workload contained 1,000 Endpoints, five direct tags per Endpoint (14 unique direct tags), and one inherited Product tag. Both runs used --batch-size 100 --progress-every 50 --benchmark --query-count.

Metric Exact base Patched
First-pass main-loop time 9.68 s 4.33 s
First-pass tag phase 5.34 s 0.20 s
First-pass queries / Endpoint (50-Endpoint chunks) 41.0-42.5 19.1-20.9
Rerun main-loop time 8.75 s 1.15 s
Rerun tag phase 7.95 s 0.23 s
Rerun queries / Endpoint (50-Endpoint chunks) 42.0-42.3 7.1

The patched runs had no tag or inheritance mismatches. After the rerun, all 6,000 Location.tags relationships, 1,000 Location.inherited_tags relationships, and all 15 counters remained correct.

This controlled workload is not a reproduction of the reporter's deployment and does not establish the same improvement for every tag distribution or at the full 65,194-Endpoint scale. The patch prevents new counter drift during this command; it does not repair counters that were already incorrect.

Documentation

No documentation change is needed because the command interface and workflow are unchanged.

Checklist

  • Targets the bugfix branch.
  • Uses a release-note-ready title.
  • Adds focused unit coverage.
  • Does not change models or require a migration.
  • Maintainer label: performance / bugfix.

@AKSHATSPAR
AKSHATSPAR force-pushed the fix/15124-bulk-migration-tags branch from da71a5e to 16c9792 Compare July 22, 2026 01:56
@AKSHATSPAR
AKSHATSPAR marked this pull request as ready for review July 22, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant