trakt improvements

This commit is contained in:
tapframe 2025-10-06 20:32:18 +05:30
parent cfa6bb8689
commit 0f5fbdf296
3 changed files with 16 additions and 16 deletions

View file

@ -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}
/>
)}
</TouchableOpacity>

View file

@ -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;

View file

@ -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<any>> = [];
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<string, number> = 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<string> = new Set();
private lastSyncTimes: Map<string, number> = 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<string, number> = 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
}