From 0f284468043ddef3128c7e152e764bb78d62b8f1 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 6 Jan 2025 19:42:45 +0100 Subject: [PATCH 1/2] 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 7e49645ce..a7d79229b 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -253,11 +253,11 @@ class update_worker(threading.Thread): 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 @@ class update_worker(threading.Thread): ) 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 @@ class update_worker(threading.Thread): # 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 @@ class update_worker(threading.Thread): 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 @@ class update_worker(threading.Thread): 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 }) From 11524108c264b7a30a0f21126a1f8e155a04f21e Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 6 Jan 2025 19:47:32 +0100 Subject: [PATCH 2/2] remove comment --- changedetectionio/update_worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index a7d79229b..28647bada 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -253,7 +253,7 @@ class update_worker(threading.Thread): pass else: - fetch_start_time = time.time() # Also used a key in history.txt + fetch_start_time = time.time() 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'): @@ -289,7 +289,7 @@ class update_worker(threading.Thread): # 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 + fetch_start_time = time.time() changed_detected, update_obj, contents = update_handler.run_changedetection(watch=watch)