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
This commit is contained in:
parent
c90544ef18
commit
b18e25e4c9
@ -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');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user