From a1d04bb37fc1f2210d7ba086ce7cd11f28e64103 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 5 Jul 2024 11:09:31 +0200 Subject: [PATCH] Snapshot count from history was not updated in watch after using [clear history] (#2459) --- changedetectionio/model/Watch.py | 2 ++ changedetectionio/store.py | 15 ++++++++------- changedetectionio/tests/test_backend.py | 11 ++++++++++- changedetectionio/update_worker.py | 3 +-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index 44157268..553f6227 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -238,6 +238,8 @@ class model(dict): if len(tmp_history): self.__newest_history_key = list(tmp_history.keys())[-1] + else: + self.__newest_history_key = None self.__history_n = len(tmp_history) diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 284f3767..5967091b 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -242,6 +242,14 @@ class ChangeDetectionStore: def clear_watch_history(self, uuid): import pathlib + # JSON Data, Screenshots, Textfiles (history index and snapshots), HTML in the future etc + for item in pathlib.Path(os.path.join(self.datastore_path, uuid)).rglob("*.*"): + unlink(item) + + # Force the attr to recalculate + bump = self.__data['watching'][uuid].history + + # Do this last because it will trigger a recheck due to last_checked being zero self.__data['watching'][uuid].update({ 'browser_steps_last_error_step' : None, 'check_count': 0, @@ -258,13 +266,6 @@ class ChangeDetectionStore: 'track_ldjson_price_data': None, }) - # JSON Data, Screenshots, Textfiles (history index and snapshots), HTML in the future etc - for item in pathlib.Path(os.path.join(self.datastore_path, uuid)).rglob("*.*"): - unlink(item) - - # Force the attr to recalculate - bump = self.__data['watching'][uuid].history - self.needs_write_urgent = True def add_watch(self, url, tag='', extras=None, tag_uuids=None, write_to_disk_now=True): diff --git a/changedetectionio/tests/test_backend.py b/changedetectionio/tests/test_backend.py index 1e1c6496..a6f735b5 100644 --- a/changedetectionio/tests/test_backend.py +++ b/changedetectionio/tests/test_backend.py @@ -3,7 +3,8 @@ import time from flask import url_for from urllib.request import urlopen -from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_rss_token_from_UI +from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, \ + extract_UUID_from_client sleep_time_for_fetch_thread = 3 @@ -141,6 +142,14 @@ def test_check_basic_change_detection_functionality(client, live_server): assert b'Mark all viewed' not in res.data assert b'unviewed' not in res.data + # #2458 "clear history" should make the Watch object update its status correctly when the first snapshot lands again + uuid = extract_UUID_from_client(client) + client.get(url_for("clear_watch_history", uuid=uuid)) + client.get(url_for("form_watch_checknow"), follow_redirects=True) + wait_for_all_checks(client) + res = client.get(url_for("index")) + assert b'preview/' in res.data + # # Cleanup everything res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True) diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index 48743f2c..daa0f788 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -250,8 +250,7 @@ class update_worker(threading.Thread): # Clear last errors (move to preflight func?) self.datastore.data['watching'][uuid]['browser_steps_last_error_step'] = None - # DeepCopy so we can be sure we don't accidently change anything by reference - watch = deepcopy(self.datastore.data['watching'].get(uuid)) + watch = self.datastore.data['watching'].get(uuid) logger.info(f"Processing watch UUID {uuid} Priority {queued_item_data.priority} URL {watch['url']}") now = time.time()