Commit 053216e
feat(data): auto-refresh stale data on the analyzer entrypoint
After every code update that adds a new field to the importer's
output shape (e.g. v0.3.0 boss_casts on fights, mana_recovery hook
on healers, the v0.2.0 stats/talent_ids on players), already-imported
data lacks the new fields and the AI prompt silently loses features.
This adds an automatic version-tag check so the next analysis touches
the affected rows and triggers a fresh fetch transparently.
Design
- Two integer-version constants in code, kept next to their importers:
``REPORT_DATA_VERSION = 3`` in ``report_service``
``TOP_LOG_DETAIL_VERSION = 2`` in ``top_logs_service``
Each is documented with a per-version changelog. Devs bump when they
change the shape — same discipline as alembic migration numbers.
``wow_localizations`` already has the equivalent via
``EXPECTED_KINDS`` (see ``workers/tasks/wow_data``); no extra
constant needed.
- Every write path stamps ``extras['_v']`` / ``detail_payload['_v']``
with the current constant. Missing ``_v`` reads as version 0 →
always stale.
- ``run_report_import`` is now smart-idempotent: if a report's
fights all carry the current ``_v`` it short-circuits as before; if
any are below, it wipes the fights (cascade to players/casts/gear/
analyses) and re-imports cleanly.
- ``refresh_top_logs_for_spec_encounter`` 's incremental cache
snapshot drops stale detail blobs so the fetch loop re-pulls them;
the post-refresh DELETE+INSERT pass then writes them back with the
current version. The analyzer's ``_fetch_top_log_references`` also
filters stale rows out at query time, so a fully-stale (spec,
encounter, metric) bucket trips the empty-refs path and naturally
triggers ``_ensure_references`` → fresh re-seed.
- ``request_analysis`` runs ``report_data_is_current`` as its first
step. If stale, it auto-invokes ``run_report_import`` and re-loads
the fight/player rows. Failures are logged and fall through with
whatever data we have rather than blocking the analysis.
Verified end-to-end against a real WCL report:
1) Fresh import: fight + player extras carry ``_v=3``.
2) Manually downgrade ``_v=1`` on every fight → ``report_data_is_current``
reports False as expected.
3) Re-run ``run_report_import`` on the stale report → fights are wiped,
re-imported, and the new fight extras carry ``_v=3`` again.
4) Same loop on top_logs: fresh refresh stamps ``_v=2``, downgrade to
``_v=1`` is detected, the next incremental refresh skips stale
cache entries and re-fetches detail; all rows end up at ``_v=2``.
User-visible effect: first analysis after an upgrade on a previously-
imported report or stale (spec, encounter, metric) takes one cycle
longer (~30-90s) while the refresh runs; subsequent analyses are
unchanged. No manual ``DELETE FROM`` dance after every release.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cc89f41 commit 053216e
3 files changed
Lines changed: 178 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
227 | 239 | | |
228 | 240 | | |
229 | 241 | | |
| |||
634 | 646 | | |
635 | 647 | | |
636 | 648 | | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
637 | 710 | | |
638 | 711 | | |
639 | 712 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
41 | 58 | | |
42 | 59 | | |
43 | 60 | | |
| |||
114 | 131 | | |
115 | 132 | | |
116 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
117 | 156 | | |
118 | 157 | | |
119 | 158 | | |
| |||
124 | 163 | | |
125 | 164 | | |
126 | 165 | | |
127 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
128 | 171 | | |
129 | 172 | | |
130 | 173 | | |
131 | 174 | | |
132 | 175 | | |
133 | 176 | | |
134 | 177 | | |
135 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
136 | 194 | | |
137 | 195 | | |
138 | 196 | | |
| |||
178 | 236 | | |
179 | 237 | | |
180 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
181 | 242 | | |
182 | 243 | | |
| 244 | + | |
183 | 245 | | |
184 | 246 | | |
185 | 247 | | |
| |||
360 | 422 | | |
361 | 423 | | |
362 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
363 | 433 | | |
364 | 434 | | |
365 | 435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
49 | 65 | | |
50 | 66 | | |
51 | 67 | | |
| |||
103 | 119 | | |
104 | 120 | | |
105 | 121 | | |
106 | | - | |
107 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
108 | 133 | | |
109 | 134 | | |
110 | 135 | | |
| |||
354 | 379 | | |
355 | 380 | | |
356 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
357 | 387 | | |
358 | 388 | | |
359 | 389 | | |
| |||
0 commit comments