Skip to content

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

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

perf(migration): batch endpoint tags and restore inheritance#15311
AKSHATSPAR wants to merge 1 commit 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

Addresses #15124.

In the reporter's completed migration of roughly 65,000 Endpoints, the benchmark summary attributed 115,317.36 seconds (99.8% of its measured phase time) to tags. The run needed several restarts, and the reporter identified tag creation as the apparent bottleneck. The command currently copies tags separately for each tagged Endpoint; on a rerun, those writes can also increase Tagulous counters without creating new relationships.

This PR:

  • collects Endpoint tags per batch, deduplicates Locations that normalize to the same URL, and writes the relationships with bulk_add_tag_mapping;
  • makes each bulk tag write atomic and retries individual Endpoints if the batch fails, preserving the command's per-row failure handling; and
  • replaces the stale LocationManager._bulk_inherit_tags call removed by perf(tag inheritance): batch_mode + per-batch bulk during import + reorganize #14877, restoring first-pass product-tag inheritance when it is enabled.

Tests

Added three focused migration tests covering:

  • batching, a final partial batch, duplicate Locations, direct and inherited tags, and a clean rerun;
  • rollback after a simulated post-write failure, followed by per-Endpoint recovery; and
  • isolation and reporting of one failing Endpoint, followed by repair on a clean rerun.

Local Docker validation:

  • migration tests: 3 passed
  • bulk-tag utility tests: 29 passed
  • tag-inheritance tests: 39 run (37 passed, 2 skipped)
  • Django system check, migration check, and Ruff 0.15.20: passed

Controlled comparison

I compared the pre-change and patched commands in separate fresh databases on the same local PostgreSQL 18 instance. 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 --benchmark --query-count.

Metric Pre-change Patched
First-pass wall time 10.49 s 4.57 s
First-pass tag phase 5.64 s 0.21 s
Rerun wall time 8.80 s 1.08 s
Rerun tag phase 7.99 s 0.22 s
Steady-state queries / Endpoint (first pass / rerun) 41.0 / 42.0 19.1 / 7.1

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

This controlled workload is not an exact reproduction of the reporter's 65,194-Endpoint deployment, so it does not establish the same improvement for every tag distribution or at that scale.

Documentation

No documentation change is needed because the command interface and user 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