From 2359818d7bdf4e925db640fa3b6d1acc9f276363 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Thu, 5 Jun 2025 21:26:11 -0500 Subject: [PATCH] Calculate stale time from start of scan not start of stale cleanup function. --- apps/m3u/tasks.py | 9 +++++---- frontend/src/components/forms/M3U.jsx | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/m3u/tasks.py b/apps/m3u/tasks.py index 9756a1f2..e5159605 100644 --- a/apps/m3u/tasks.py +++ b/apps/m3u/tasks.py @@ -496,7 +496,7 @@ def process_m3u_batch(account_id, batch, groups, hash_keys): return retval -def cleanup_streams(account_id): +def cleanup_streams(account_id, scan_start_time=timezone.now): account = M3UAccount.objects.get(id=account_id, is_active=True) existing_groups = ChannelGroup.objects.filter( m3u_account__m3u_account=account, @@ -505,7 +505,7 @@ def cleanup_streams(account_id): logger.info(f"Found {len(existing_groups)} active groups for M3U account {account_id}") # Calculate cutoff date for stale streams - stale_cutoff = timezone.now() - timezone.timedelta(days=account.stale_stream_days) + stale_cutoff = scan_start_time - timezone.timedelta(days=account.stale_stream_days) logger.info(f"Removing streams not seen since {stale_cutoff} for M3U account {account_id}") # Delete streams that are not in active groups @@ -833,7 +833,8 @@ def refresh_single_m3u_account(account_id): return f"Task already running for account_id={account_id}." # Record start time - start_time = time.time() + refresh_start_timestamp = timezone.now() # For the cleanup function + start_time = time.time() # For tracking elapsed time as float streams_created = 0 streams_updated = 0 streams_deleted = 0 @@ -1077,7 +1078,7 @@ def refresh_single_m3u_account(account_id): Stream.objects.filter(id=-1).exists() # This will never find anything but ensures DB sync # Now run cleanup - cleanup_streams(account_id) + cleanup_streams(account_id, refresh_start_timestamp) # Calculate elapsed time elapsed_time = time.time() - start_time diff --git a/frontend/src/components/forms/M3U.jsx b/frontend/src/components/forms/M3U.jsx index caa7ae31..24ddd377 100644 --- a/frontend/src/components/forms/M3U.jsx +++ b/frontend/src/components/forms/M3U.jsx @@ -324,7 +324,7 @@ const M3U = ({ />