Skip to content

Gate page-count and publish-year banners on per-stat pending flags#104

Merged
vanajmoorthy merged 3 commits into
mainfrom
fix/per-stat-enrichment-flags
May 5, 2026
Merged

Gate page-count and publish-year banners on per-stat pending flags#104
vanajmoorthy merged 3 commits into
mainfrom
fix/per-stat-enrichment-flags

Conversation

@vanajmoorthy
Copy link
Copy Markdown
Owner

Summary

The "Still enriching" banner showed up on stats that didn't actually need enrichment for users uploading Goodreads CSVs (which include Number of Pages and Original Publication Year per row).

Root cause: a single global enrichment.pending flag (Count(google_books_last_checked NOT NULL) < total) gated banners on three stats whose values were already final from the CSV — Total Pages Read, Average Book Length, and Average Book Age.

Fix

Added two per-stat flags to _compute_enrichment_progress:

  • length_pending — true iff any book has page_count IS NULL
  • year_pending — true iff any book has publish_year IS NULL

The three affected banners now gate on these flags instead of the global one. Genre/fiction-split/mainstream banners still use the global flag because they genuinely depend on enrichment-derived data.

The Alpine x-show="$store.enrichment?.pending" binding stays on the inline banners so they vanish the moment global enrichment finishes (instead of waiting for the page reload).

Behaviour

  • Goodreads upload: page count + publish year are populated at sync time → both new flags are False → those three banners never render. Genre/mainstream banners still show until enrichment completes.
  • StoryGraph upload: neither field is in the CSV → both flags stay True until enrichment fills them in → banners show as before.
  • Mid-enrichment: each stat's banner clears as soon as the underlying data is complete, independent of the global flag.

Test plan

  • Added 4 tests to EnrichmentCompletionDetectionTests covering both flags True/False
  • Existing 5 tests in same class still pass
  • core.tests.test_views_e2e + core.tests.test_storygraph_integration (27 tests) all pass
  • Manual: upload csv/test-csvs/goodreads_alien_batch3.csv, confirm Total Pages Read / Avg Book Length / Avg Book Age don't show "Still enriching"
  • Manual: upload a StoryGraph CSV and confirm those three banners DO show until enrichment completes

The "Still enriching" banner on Total Pages Read, Average Book Length, and
Average Book Age was driven by the global enrichment.pending flag, which
stays true until every book has been API-checked. Goodreads CSVs supply
both fields per row, so those banners showed throughout enrichment even
though the values were already final.

Add length_pending / year_pending flags computed from actual missing
data (any book with NULL page_count / publish_year) and gate the three
affected banners on those instead.

Other stats (genres, fiction split, mainstream score) still use the
global flag — they genuinely depend on enrichment.
…ia Alpine

Address review feedback on top of the per-stat banner change:

- Parameterize enrichment_banner.html with `condition` (required) and
  `store_key` (optional, default "pending") so all 5 callers share one
  source of truth instead of inlining.

- Bind opacity-60 wrapper via Alpine `:class` (in addition to server-side
  rendering for FOUC) so dimming clears live mid-poll without waiting for
  the page reload.

- Bind banner `x-show` to per-stat Alpine store keys so the cross-flag
  asymmetry between server gate and live binding is gone.

- Update Alpine store init + poll() to seed and update per-stat flags.

- Rename length_pending → pages_any_missing, year_pending → year_any_missing
  to disambiguate from the existing pages_pending (50%-done sparseness
  threshold for skeletons).
@vanajmoorthy vanajmoorthy merged commit 04a6f72 into main May 5, 2026
1 check passed
@vanajmoorthy vanajmoorthy deleted the fix/per-stat-enrichment-flags branch May 5, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant