Calculate stale time from start of scan not start of stale cleanup function.

This commit is contained in:
SergeantPanda 2025-06-05 21:26:11 -05:00
parent 5e2757f578
commit 2359818d7b
2 changed files with 6 additions and 5 deletions

View file

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

View file

@ -324,7 +324,7 @@ const M3U = ({
/>
<NumberInput
min={1}
min={0}
max={365}
label="Stale Stream Retention (days)"
description="Streams not seen for this many days will be removed"