-- Delisting xxxfreewatch 2026-05-18: 790 scenes, 0% canonical match, 100% solo-orphan.
-- Pure orphan factory. CF-walled from VPS but even mobile WebView 0/790 ever matched TPDB/StashDB.

BEGIN;

CREATE TEMP TABLE _xxxfw_solo AS
SELECT s.id AS scene_id
FROM scenes s
WHERE EXISTS (
  SELECT 1 FROM playback_sources ps
  WHERE ps.scene_id = s.id AND ps.origin = 'tube:xxxfreewatch' AND ps.dead_at IS NULL
)
AND NOT EXISTS (
  SELECT 1 FROM playback_sources ps2
  WHERE ps2.scene_id = s.id AND ps2.origin <> 'tube:xxxfreewatch' AND ps2.dead_at IS NULL
);

SELECT COUNT(*) AS solo_to_delete FROM _xxxfw_solo;

UPDATE playback_sources
SET dead_at = NOW(),
    dead_reason = 'Delisted 2026-05-18 (0% canonical match, 100% solo-orphan, CF-walled)'
WHERE origin = 'tube:xxxfreewatch' AND dead_at IS NULL;

DELETE FROM scene_tags WHERE scene_id IN (SELECT scene_id FROM _xxxfw_solo);
DELETE FROM scene_performers WHERE scene_id IN (SELECT scene_id FROM _xxxfw_solo);
DELETE FROM favorite_scenes WHERE scene_id IN (SELECT scene_id FROM _xxxfw_solo);
DELETE FROM scene_play_progress WHERE scene_id IN (SELECT scene_id FROM _xxxfw_solo);
DELETE FROM scene_fingerprints WHERE scene_id IN (SELECT scene_id FROM _xxxfw_solo);
DELETE FROM scene_external_refs WHERE scene_id IN (SELECT scene_id FROM _xxxfw_solo);
DELETE FROM playback_sources WHERE scene_id IN (SELECT scene_id FROM _xxxfw_solo);
DELETE FROM scenes WHERE id IN (SELECT scene_id FROM _xxxfw_solo);

COMMIT;

SELECT
  COUNT(*) FILTER (WHERE dead_at IS NULL) AS live_remaining,
  COUNT(*) FILTER (WHERE dead_at IS NOT NULL) AS dead_total
FROM playback_sources
WHERE origin = 'tube:xxxfreewatch';
