From 0f284468043ddef3128c7e152e764bb78d62b8f1 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 6 Jan 2025 19:42:45 +0100 Subject: [PATCH] Be more specific about 'change time' --- changedetectionio/update_worker.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index 7e49645ce61..a7d79229bc6 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -253,11 +253,11 @@ def run(self): pass else: + fetch_start_time = time.time() # Also used a key in history.txt uuid = queued_item_data.item.get('uuid') self.current_uuid = uuid if uuid in list(self.datastore.data['watching'].keys()) and self.datastore.data['watching'][uuid].get('url'): changed_detected = False - fetch_start_time = round(time.time()) # Also used a key in history.txt contents = b'' process_changedetection_results = True update_obj = {} @@ -286,6 +286,11 @@ def run(self): ) update_handler.call_browser() + + # In reality, the actual time of when the change was detected could be a few seconds after this + # For example it should include when the page stopped rendering if using a playwright/chrome type fetch + fetch_start_time = time.time() # Also used a key in history.txt + changed_detected, update_obj, contents = update_handler.run_changedetection(watch=watch) # Re #342 @@ -538,6 +543,7 @@ def run(self): # Small hack so that we sleep just enough to allow 1 second between history snapshots # this is because history.txt indexes/keys snapshots by epoch seconds and we dont want dupe keys + # @also - the keys are one per second at the most (for now) if watch.newest_history_key and int(fetch_start_time) == int(watch.newest_history_key): logger.warning( f"Timestamp {fetch_start_time} already exists, waiting 1 seconds so we have a unique key in history.txt") @@ -545,14 +551,14 @@ def run(self): time.sleep(1) watch.save_history_text(contents=contents, - timestamp=fetch_start_time, + timestamp=int(fetch_start_time), snapshot_id=update_obj.get('previous_md5', 'none')) empty_pages_are_a_change = self.datastore.data['settings']['application'].get('empty_pages_are_a_change', False) if update_handler.fetcher.content or (not update_handler.fetcher.content and empty_pages_are_a_change): # attribute .last_changed is then based on this data - watch.save_last_fetched_html(contents=update_handler.fetcher.content, timestamp=fetch_start_time) + watch.save_last_fetched_html(contents=update_handler.fetcher.content, timestamp=int(fetch_start_time)) # Notifications should only trigger on the second time (first time, we gather the initial snapshot) if watch.history_n >= 2: @@ -581,7 +587,7 @@ def run(self): pass self.datastore.update_watch(uuid=uuid, update_obj={'fetch_time': round(time.time() - fetch_start_time, 3), - 'last_checked': fetch_start_time, + 'last_checked': int(fetch_start_time), 'check_count': count })