From d8f0700ff65e158ddc9eecdf2a110a9b799c5570 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sun, 4 May 2025 13:59:06 -0500 Subject: [PATCH] Fix last_seen not being wrote to properly. --- apps/m3u/tasks.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/m3u/tasks.py b/apps/m3u/tasks.py index 2b7cd0ec..4f119c2e 100644 --- a/apps/m3u/tasks.py +++ b/apps/m3u/tasks.py @@ -260,6 +260,9 @@ def process_xc_category(account_id, batch, groups, hash_keys): streams_to_update.append(obj) del existing_streams[stream_hash] else: + # Always update last_seen, even if nothing else changed + obj.last_seen = timezone.now() + streams_to_update.append(obj) existing_streams[stream_hash] = obj else: stream_props["last_seen"] = timezone.now() @@ -270,9 +273,9 @@ def process_xc_category(account_id, batch, groups, hash_keys): if streams_to_create: Stream.objects.bulk_create(streams_to_create, ignore_conflicts=True) if streams_to_update: - Stream.objects.bulk_update(streams_to_update, { key for key in stream_props.keys() if key not in ["m3u_account", "stream_hash"] and key not in hash_keys}) - # if len(existing_streams.keys()) > 0: - # Stream.objects.bulk_update(existing_streams.values(), ["last_seen"]) + Stream.objects.bulk_update(streams_to_update, { key for key in stream_props.keys() if key not in ["m3u_account", "stream_hash"] and key not in hash_keys} | {"last_seen"}) + if len(existing_streams.keys()) > 0: + Stream.objects.bulk_update(existing_streams.values(), ["last_seen"]) except Exception as e: logger.error(f"Bulk create failed: {str(e)}") @@ -339,6 +342,9 @@ def process_m3u_batch(account_id, batch, groups, hash_keys): streams_to_update.append(obj) del existing_streams[stream_hash] else: + # Always update last_seen, even if nothing else changed + obj.last_seen = timezone.now() + streams_to_update.append(obj) existing_streams[stream_hash] = obj else: stream_props["last_seen"] = timezone.now() @@ -349,7 +355,7 @@ def process_m3u_batch(account_id, batch, groups, hash_keys): if streams_to_create: Stream.objects.bulk_create(streams_to_create, ignore_conflicts=True) if streams_to_update: - Stream.objects.bulk_update(streams_to_update, { key for key in stream_props.keys() if key not in ["m3u_account", "stream_hash"] and key not in hash_keys}) + Stream.objects.bulk_update(streams_to_update, { key for key in stream_props.keys() if key not in ["m3u_account", "stream_hash"] and key not in hash_keys} | {"last_seen"}) if len(existing_streams.keys()) > 0: Stream.objects.bulk_update(existing_streams.values(), ["last_seen"]) except Exception as e: