Commit e8c0959
committed
perf(tags): replace inherited_tags TagField with _inherited_tag_names JSONField
Phase B Stage 3 of the tag inheritance redesign. Replaces the duplicate
`inherited_tags` TagField on Engagement / Test / Finding / Endpoint /
Location with a single `_inherited_tag_names` JSONField (Postgres
`jsonb`). Drops 5 auto-generated through tables, 5 Tagulous tag tables,
and 8 pghistory proxy/event models tied to the through tables. The new
column carries an inverted GIN index so "find children that inherited
tag X" remains efficient.
Code changes
------------
- Models: 5x TagField -> JSONField. Migration 0265 copies existing M2M
data into the JSON column, drops the field (Django removes the
through table), drops the orphan pghistory and Tagulous models, and
adds the GIN indexes.
- `_manage_inherited_tags` / `propagate_inheritance` rewritten to read
and write the JSON column. The `tags` M2M is only mutated when its
contents actually need to change.
- `_sync_inheritance_for_qs` reads `_inherited_tag_names` directly from
each child instead of joining the through table; performs a bulk
UPDATE per (target name set) group instead of per (model, tag) pair.
Bulk re-merge dedup avoids double-writing the same (child, name) pair.
- `LocationManager._bulk_inherit_tags` reads JSON column rather than
the inherited_tags through table.
- `tag_inheritance.flush_for_product` short-circuits when tag
inheritance is disabled so importers don't pay for it on every scan.
Plumbing
--------
- `Meta.exclude` lists in forms / filters / api serializers updated
from `inherited_tags` -> `_inherited_tag_names`.
- `DojoFilter.filter_for_field` skips JSONField auto-generation for
`_inherited_tag_names` (django-filter raises on JSONField).
- Auditlog `tag_through_models` and `backfill.py` drop the inherited_tags
proxies; pghistory now captures changes via the parent table's event.
- `dojo_testdata.json` fixture renames `"inherited_tags": []` ->
`"_inherited_tag_names": []`.
- Tests using `.inherited_tags.all()` switched to read
`_inherited_tag_names`.
Pinned perf-test impact (this branch vs Stage 2)
-----------------------------------------------
ZAP scan import V2 : 1006 -> 700 (~30% drop)
ZAP scan import V3 : 984 -> 698 (~29% drop)
ZAP reimport V2 (no change) : 82 -> 78 (~5% drop)
ZAP reimport V3 (no change) : 140 -> 136 (~3% drop)
Product tag add -> 100 findings V2/V3 : 94 -> 58 (~38% drop)
Product tag remove -> 100 findings V2/V3 : 56 -> 38 (~32% drop)
Product tag add -> 100 endpoints V2 : 194 -> 58 (~70% drop)
Product tag remove -> 100 endpoints V2 : 56 -> 38 (~32% drop)
Product tag add -> 100 locations V3 : 320 -> 272 (~15% drop)
Product tag remove -> 100 locations V3 : 270 -> 246 (~9% drop)
Create 1 finding under inheritance : 64 -> 42 (~34% drop)
Create 100 findings under inheritance : 4024 -> 2814 (~30% drop)
Finding add user tag (sticky) : 17 -> 16
Finding remove inherited tag (sticky) : 44 -> 24 (~45% drop)
`test_importers_performance.py` baselines are unaffected because the
flush_for_product call short-circuits when inheritance is disabled
(the fixture used by those tests has it off).
Migration notes
---------------
- Destructive: drops 5 inherited_tags through tables and the 5 Tagulous
tag-name tables that backed them. Forward-only.
- Postgres only. Uses native `jsonb` + GIN index on the column.
- Must be applied with a fresh DB or `--rebuilddb` in test environments;
`--keepdb` will not pick up the schema change.1 parent 999f576 commit e8c0959
17 files changed
Lines changed: 502 additions & 189 deletions
File tree
- dojo
- api_v2
- auditlog
- db_migrations
- fixtures
- importers
- location
- product
- unittests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1110 | 1110 | | |
1111 | 1111 | | |
1112 | 1112 | | |
1113 | | - | |
| 1113 | + | |
1114 | 1114 | | |
1115 | 1115 | | |
1116 | 1116 | | |
| |||
1282 | 1282 | | |
1283 | 1283 | | |
1284 | 1284 | | |
1285 | | - | |
| 1285 | + | |
1286 | 1286 | | |
1287 | 1287 | | |
1288 | 1288 | | |
| |||
1418 | 1418 | | |
1419 | 1419 | | |
1420 | 1420 | | |
1421 | | - | |
| 1421 | + | |
1422 | 1422 | | |
1423 | 1423 | | |
1424 | 1424 | | |
| |||
1442 | 1442 | | |
1443 | 1443 | | |
1444 | 1444 | | |
1445 | | - | |
| 1445 | + | |
1446 | 1446 | | |
1447 | 1447 | | |
1448 | 1448 | | |
| |||
1746 | 1746 | | |
1747 | 1747 | | |
1748 | 1748 | | |
1749 | | - | |
| 1749 | + | |
1750 | 1750 | | |
1751 | 1751 | | |
1752 | 1752 | | |
| |||
1967 | 1967 | | |
1968 | 1968 | | |
1969 | 1969 | | |
1970 | | - | |
| 1970 | + | |
1971 | 1971 | | |
1972 | 1972 | | |
1973 | 1973 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 60 | | |
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
67 | 64 | | |
68 | 65 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | 66 | | |
73 | 67 | | |
74 | 68 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | 69 | | |
79 | 70 | | |
80 | 71 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | 72 | | |
85 | 73 | | |
86 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
401 | 405 | | |
402 | | - | |
403 | 406 | | |
404 | 407 | | |
405 | | - | |
406 | 408 | | |
407 | | - | |
408 | 409 | | |
409 | | - | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| |||
Lines changed: 124 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
0 commit comments