channel stats caching, plan-based sync limits, and dashboard architecture refactor#199
Open
GauravOP-03 wants to merge 5 commits into
Open
channel stats caching, plan-based sync limits, and dashboard architecture refactor#199GauravOP-03 wants to merge 5 commits into
GauravOP-03 wants to merge 5 commits into
Conversation
… dashboard modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This PR improves the YouTube Channel Stats flow across database, backend, and frontend.
Primary goals:
Changed File Structure (only touched paths)
Database / Migration Changes
File
packages/supabase/migrations/20260429125432_plans_v2.sqlWhat changed
planstable enhancementsdaily_limit int not null default 5cooldown_minutes int not null default 60youtube_channelscaching + usage fieldstop_videos jsonbrecent_videos jsonblast_synced_at timestamptzlast_used_at timestamptzusage_count int not null default 0usage_reset_date date not null default current_dateyoutube_trained_videos jsonbAdded function:
use_feature(p_user_id uuid)allowed,reason,remaining,daily_limit, etc.).Added function:
get_feature_usage(p_user_id uuid)can_use_now.Detailed function behavior (
use_featureandget_feature_usage)use_feature(p_user_id uuid)- write path (consume one usage)This function is called when user performs an action that should consume quota (for example, force sync).
Step-by-step working:
Resolve applicable plan limits
subscriptions->plans.daily_limitplan when multiple active rows exist.starterplan.daily_limit = 5cooldown_minutes = 60Load usage state from
youtube_channelsusage_count,last_used_at, andusage_reset_date.usage_reset_dateis from a previous day (or null), it treats usage as reset:usage_count = 0last_used_at = nullEnforce cooldown first
allowed: falsereason: "cooldown"minutes_remainingEnforce daily limit second
usage_count >= daily_limit:allowed: falsereason: "daily_limit"Atomically consume one usage
youtube_channelsin one SQL update:usage_count(or sets to1if day rolled over)usage_reset_date = current_datelast_used_at = now()allowed: trueWhy this is useful:
get_feature_usage(p_user_id uuid)- read path (status only)This function is called when frontend only needs current usage status (without consuming quota).
Step-by-step working:
usage_count,last_used_at, andusage_reset_datefromyoutube_channels.0).max(cooldown_minutes - minutes_since_last_used, 0).plan,usage_count,remaining,daily_limit,cooldown_minutes,cooldown_remaining,can_use_now(trueonly when cooldown elapsed and daily limit not reached).Why this is useful:
Sync nowvs disabled with reason).Combined design benefit
Using both functions together creates a clean control loop:
get_feature_usagetells frontend whether action is currently available.use_featureis the single authority that actually consumes quota.This pattern improves correctness, UX clarity, and long-term maintainability.
Why these decisions and their benefits
Plan-level config in
plans(daily_limit,cooldown_minutes)Channel stats caching in
youtube_channelsuse_feature+get_feature_usagesplituse_feature: permission check + usage consumeget_feature_usage: read-only statusMigration execution status
20260429125432_plans_v2.sqlare live in production.Backend (NestJS) Changes
Files
apps/api/src/youtube/youtube.controller.tsapps/api/src/youtube/youtube.service.tsWhat changed
use_feature,get_feature_usage).youtube_channels.Important bug fix included
custom_url,country,default_language, andthumbnailfrom the updated selected row (not from token-only prefetch), preventing undefined metadata in sync response.Frontend Changes
Dashboard refactor (main experience)
Files
apps/web/components/dashboard/main/DashboardHome.tsxapps/web/components/dashboard/main/ConnectedDashboardView.tsxapps/web/components/dashboard/main/OnboardingDashboardView.tsxapps/web/components/dashboard/main/SharedComponents.tsxapps/web/components/dashboard/main/types.tsapps/web/components/dashboard/main/utils.tsapps/web/components/dashboard/main/skeleton/DashboardSkeleton.tsxWhat changed
SharedComponents.Design pattern followed
DashboardHomeorchestrates state and routing decisions.ConnectedDashboardViewandOnboardingDashboardViewfocus on UI rendering.main/.Benefits
Channel Stats Frontend Feature
Files
apps/web/app/dashboard/channel-stats/page.tsxapps/web/components/dashboard/channel-stats/ChannelStatsError.tsxapps/web/components/dashboard/channel-stats/Skeleton.tsxapps/web/components/dashboard/channel-stats/util.tsapps/web/hooks/useChannelStats.tsapps/web/next.config.mjsWhat changed
useChannelStatshook for fetch/loading/error orchestration.Benefits
Validation Package Updates
Files
packages/validations/src/types/youtubeStatsTypes.tspackages/validations/src/index.tsWhat changed
Benefits
User Impact
Suggested Test Plan
custom_urlcountrydefault_languagethumbnailplans.daily_limit/plans.cooldown_minutes.