Files
civitai__civitai/prisma/programmability
Manuel Emilio Urena 6b58d1fa89 fix(models): cascade nsfw flip to version rollups (#2288)
When Model.nsfw was true, every ModelVersion.nsfwLevel was stamped to
nsfwBrowsingLevelsFlag (60 = R|X|XXX|Blocked). The old Model trigger
only enqueued a Model-level UpdateNsfwLevel job on nsfw flip, so after
a true->false flip the versions stayed at 60. updateModelNsfwLevels
then bit_or'd the stale 60s back to 60 and the WHERE clause found no
diff — model frozen, hidden from .com search.

Trigger now enqueues a ModelVersion UpdateNsfwLevel job for every
Published version under the model whenever Model.nsfw changes. The
update-nsfw-levels cron processes versions before models in the same
tick (see updateNsfwLevels batch order), so the rollup reads fresh
version data. Also swapped the prior `!=` comparison to
IS DISTINCT FROM for NULL-safety.

Backfill: a hidden debug endpoint at
src/pages/api/testing/backfill-stale-nsfw-rollups.ts (guarded by
WEBHOOK_TOKEN) enqueues UpdateNsfwLevel jobs for the existing stuck
cohort (~3,198 models / ~5,264 versions). Supports count, enqueue
(with dryRun / limit / modelId), and verify actions.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 11:47:45 -04:00
..
2024-07-29 20:53:34 -06:00
2025-02-18 11:49:31 -04:00
2023-12-06 11:49:09 -07:00