mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-21 01:05:30 +00:00
Cleanup orphaned channels if stale stream retention deleted the last stream from the channel and was created by auto channel sync for the current m3u.
This commit is contained in:
parent
fc2caa0e12
commit
b17bc21159
1 changed files with 21 additions and 0 deletions
|
|
@ -1829,6 +1829,27 @@ def sync_auto_channels(account_id, scan_start_time=None):
|
|||
f"Deleted {deleted_count} auto channels for removed streams"
|
||||
)
|
||||
|
||||
# Additional cleanup: Remove auto-created channels that no longer have any valid streams
|
||||
# This handles the case where streams were deleted due to stale retention policy
|
||||
orphaned_channels = Channel.objects.filter(
|
||||
auto_created=True,
|
||||
auto_created_by=account
|
||||
).exclude(
|
||||
# Exclude channels that still have valid stream associations
|
||||
id__in=ChannelStream.objects.filter(
|
||||
stream__m3u_account=account,
|
||||
stream__isnull=False
|
||||
).values_list('channel_id', flat=True)
|
||||
)
|
||||
|
||||
orphaned_count = orphaned_channels.count()
|
||||
if orphaned_count > 0:
|
||||
orphaned_channels.delete()
|
||||
channels_deleted += orphaned_count
|
||||
logger.info(
|
||||
f"Deleted {orphaned_count} orphaned auto channels with no valid streams"
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Auto channel sync complete for account {account.name}: {channels_created} created, {channels_updated} updated, {channels_deleted} deleted"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue