From b18e25e4c9e166cd28f0aa33eb072c7af9b7289a Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Thu, 28 Aug 2025 20:52:15 +0000 Subject: [PATCH] Improve video synchronization by adjusting fetching logic and adding delays Adjust the video synchronization service to correctly determine if more pages of videos exist by checking the total fetched count against the total available videos and the number of videos returned per page. A small delay is introduced between paginated requests to prevent potential rate limiting issues from the video source. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2eb1084e-b728-4449-9231-f1665924c8d5 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2eb1084e-b728-4449-9231-f1665924c8d5/h92OTmA --- server/videoSync.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/videoSync.ts b/server/videoSync.ts index 3ebeee0..36a7eba 100644 --- a/server/videoSync.ts +++ b/server/videoSync.ts @@ -38,12 +38,17 @@ class VideoSyncService { allVideos = allVideos.concat(result.videos); // Check if there are more pages - const totalFetched = (page - 1) * itemsPerPage + result.videos.length; - hasMore = totalFetched < result.total && result.videos.length === itemsPerPage; + const totalFetched = allVideos.length; + hasMore = totalFetched < result.total && result.videos.length > 0; console.log(`📊 Page ${page}: ${result.videos.length} videos (Total so far: ${allVideos.length}/${result.total})`); page++; + // Add small delay to avoid rate limiting + if (hasMore) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + // Safety limit to prevent infinite loops if (page > 100) { console.log('⚠️ Reached page limit (100), stopping fetch');