Skip to content

feat: redesign YouTube stats tracking with Supabase pipeline#595

Merged
codercatdev merged 3 commits intodevfrom
feat/youtube-stats-supabase-v2
Mar 3, 2026
Merged

feat: redesign YouTube stats tracking with Supabase pipeline#595
codercatdev merged 3 commits intodevfrom
feat/youtube-stats-supabase-v2

Conversation

@codercatdev
Copy link
Contributor

Summary

Redesigns YouTube stats from Sanity youtubeUpdateTask to a 3-phase Supabase pipeline (Discover → Fetch → Sync). Reduces Sanity API calls from 3N+ to only-when-changed writes.

9 files, +772/-415 lines

New

  • lib/youtube-stats.ts — shared library (discover/fetch/sync)
  • supabase/migrations/001_youtube_stats.sql — table + indexes + RPC
  • docs/youtube-stats-architecture.md — architecture doc
  • app/api/youtube/cleanup/route.tsx — one-time cleanup (delete after use)

Modified

  • app/api/youtube/views/route.tsx — simplified (349→54 lines)
  • app/api/cron/route.tsx — forwards ?action= param

Removed

  • youtubeUpdateTask schema, config registration, types

Review

  • All routes auth-protected ✅
  • Supabase service role key (server-side only) ✅
  • YouTube API batching (50/request) ✅
  • Idempotent upserts ✅
  • Zero orphaned references ✅

Suggestions (non-blocking)

  1. Add RLS to youtube_stats table
  2. Use RPC function instead of JS filtering in pushStatsToSanity
  3. Remove duplicate queryError check
  4. Add action parameter validation

- Replace Sanity-based youtubeUpdateTask queue with Supabase youtube_stats table
- New 3-phase pipeline: discover → fetch → sync (lib/youtube-stats.ts)
- Route reduced from 349 to 54 lines (85% reduction)
- Sanity only written to when stats actually change
- Remove youtubeUpdateTask schema, types, and config references
- Add Supabase migration for youtube_stats table with indexes and RPC
- Update cron route to forward ?action= param for phase-specific runs
- Add cleanup route to delete existing youtubeUpdateTask documents
- Add architecture documentation

Co-authored-by: youtubeviews <youtubeviews@miriad.systems>
@vercel
Copy link

vercel bot commented Mar 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
codingcat-dev Ready Ready Preview, Comment Mar 3, 2026 6:29pm

@codercatdev
Copy link
Contributor Author

✅ Code Review Complete — Ready to merge

Reviewed by @pm — solid redesign. 9 files, +772/-415 lines.

Strengths

  • Excellent 3-phase pipeline (Discover → Fetch → Sync)
  • Massive reduction in Sanity API calls (3N+ → only-when-changed)
  • All routes auth-protected with CRON_SECRET
  • Idempotent upserts, YouTube API batching (50/req)
  • Clean schema removal with zero orphaned references
  • Good architecture documentation

Non-blocking suggestions for follow-up

  1. Add RLS to youtube_stats table
  2. Use the RPC function instead of JS filtering in pushStatsToSanity
  3. Remove duplicate queryError check (~line 293 vs 306)
  4. Add ?action= parameter validation on the views route

No blockers — good to merge to dev! 🚀

Miriad and others added 2 commits March 3, 2026 18:18
Co-authored-by: youtubeviews <youtubeviews@miriad.systems>
Co-authored-by: youtubeviews <youtubeviews@miriad.systems>
@codercatdev codercatdev merged commit d122920 into dev Mar 3, 2026
2 of 3 checks passed
@codercatdev codercatdev deleted the feat/youtube-stats-supabase-v2 branch March 5, 2026 01:53
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