From 0f5fbdf2967d0ae22b0186d30b6fa600d98cbb02 Mon Sep 17 00:00:00 2001 From: tapframe Date: Mon, 6 Oct 2025 20:32:18 +0530 Subject: [PATCH] trakt improvements --- src/components/player/AndroidVideoPlayer.tsx | 4 ++-- src/hooks/useTraktAutosync.ts | 8 ++++---- src/services/traktService.ts | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/components/player/AndroidVideoPlayer.tsx b/src/components/player/AndroidVideoPlayer.tsx index fda57e10..c64005d4 100644 --- a/src/components/player/AndroidVideoPlayer.tsx +++ b/src/components/player/AndroidVideoPlayer.tsx @@ -3409,8 +3409,8 @@ const AndroidVideoPlayer: React.FC = () => { allowsExternalPlayback={false as any} preventsDisplaySleepDuringVideoPlayback={true as any} // ExoPlayer HLS optimization - let the player use optimal defaults - // Use textureView on Android: allows 3D mapping but DRM not supported - viewType={Platform.OS === 'android' ? ViewType.TEXTURE : undefined} + // Use surfaceView on Android for improved compatibility + viewType={Platform.OS === 'android' ? ViewType.SURFACE : undefined} /> )} diff --git a/src/hooks/useTraktAutosync.ts b/src/hooks/useTraktAutosync.ts index b6d300ae..225ee17f 100644 --- a/src/hooks/useTraktAutosync.ts +++ b/src/hooks/useTraktAutosync.ts @@ -196,8 +196,8 @@ export function useTraktAutosync(options: TraktAutosyncOptions) { // BACKGROUND: Periodic sync - use queued method const progressDiff = Math.abs(progressPercent - lastSyncProgress.current); - // Only skip if not forced and progress difference is minimal (< 1%) - if (progressDiff < 1) { + // Only skip if not forced and progress difference is minimal (< 0.5%) + if (progressDiff < 0.5) { return; } @@ -265,8 +265,8 @@ export function useTraktAutosync(options: TraktAutosyncOptions) { let useImmediate = reason === 'user_close'; // IMMEDIATE SYNC: Remove debouncing for instant sync when closing - // Only prevent truly duplicate calls (within 1 second for regular, 200ms for immediate) - const debounceThreshold = useImmediate ? 200 : 1000; + // Only prevent truly duplicate calls (within 500ms for regular, 100ms for immediate) + const debounceThreshold = useImmediate ? 100 : 500; if (!isSignificantUpdate && now - lastStopCall.current < debounceThreshold) { logger.log(`[TraktAutosync] Ignoring duplicate stop call within ${debounceThreshold}ms (reason: ${reason})`); return; diff --git a/src/services/traktService.ts b/src/services/traktService.ts index 0b4e1893..c5a11131 100644 --- a/src/services/traktService.ts +++ b/src/services/traktService.ts @@ -561,9 +561,9 @@ export class TraktService { private tokenExpiry: number = 0; private isInitialized: boolean = false; - // Rate limiting + // Rate limiting - Optimized for real-time scrobbling private lastApiCall: number = 0; - private readonly MIN_API_INTERVAL = 3000; // Minimum 3 seconds between API calls (further reduce heating) + private readonly MIN_API_INTERVAL = 1000; // Reduced from 3000ms to 1000ms for real-time updates private requestQueue: Array<() => Promise> = []; private isProcessingQueue: boolean = false; @@ -572,14 +572,14 @@ export class TraktService { private readonly SCROBBLE_EXPIRY_MS = 46 * 60 * 1000; // 46 minutes (based on Trakt's expiry window) private scrobbledTimestamps: Map = new Map(); - // Track currently watching sessions to avoid duplicate starts// Sync debouncing + // Track currently watching sessions to avoid duplicate starts// Sync debouncing - Optimized for real-time updates private currentlyWatching: Set = new Set(); private lastSyncTimes: Map = new Map(); - private readonly SYNC_DEBOUNCE_MS = 20000; // 20 seconds to further reduce API calls + private readonly SYNC_DEBOUNCE_MS = 5000; // Reduced from 20000ms to 5000ms for real-time updates - // Debounce for stop calls + // Debounce for stop calls - Optimized for responsiveness private lastStopCalls: Map = new Map(); - private readonly STOP_DEBOUNCE_MS = 3000; // 3 seconds to avoid duplicate stop calls + private readonly STOP_DEBOUNCE_MS = 1000; // Reduced from 3000ms to 1000ms for better responsiveness // Default completion threshold (overridden by user settings) private readonly DEFAULT_COMPLETION_THRESHOLD = 80; // 80% @@ -1767,8 +1767,8 @@ export class TraktService { const watchingKey = this.getWatchingKey(contentData); const lastSync = this.lastSyncTimes.get(watchingKey) || 0; - // IMMEDIATE SYNC: Remove debouncing for instant sync, only prevent truly rapid calls (< 500ms) - if (!force && (now - lastSync) < 500) { + // IMMEDIATE SYNC: Remove debouncing for instant sync, only prevent truly rapid calls (< 300ms) + if (!force && (now - lastSync) < 300) { return true; // Skip this sync, but return success } @@ -1874,9 +1874,9 @@ export class TraktService { const watchingKey = this.getWatchingKey(contentData); - // MINIMAL DEDUPLICATION: Only prevent calls within 100ms for immediate actions + // MINIMAL DEDUPLICATION: Only prevent calls within 50ms for immediate actions const lastSync = this.lastSyncTimes.get(watchingKey) || 0; - if ((Date.now() - lastSync) < 100) { + if ((Date.now() - lastSync) < 50) { return true; // Skip this sync, but return success }