From 77b59809ca8bcd37db9b6aae5eae8d5d84314a4c Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 28 Oct 2022 18:36:07 +0200 Subject: [PATCH] Removing unused code (#1070) --- changedetectionio/__init__.py | 2 -- changedetectionio/fetch_site_status.py | 3 --- changedetectionio/model/Watch.py | 6 ++++++ changedetectionio/tests/test_backend.py | 12 ++++++------ changedetectionio/tests/util.py | 1 + 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 383c5bf7..d379c2f8 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -199,8 +199,6 @@ def changedetection_app(config=None, datastore_o=None): - - # Setup cors headers to allow all domains # https://flask-cors.readthedocs.io/en/latest/ # CORS(app) diff --git a/changedetectionio/fetch_site_status.py b/changedetectionio/fetch_site_status.py index 54587dff..03f4579d 100644 --- a/changedetectionio/fetch_site_status.py +++ b/changedetectionio/fetch_site_status.py @@ -185,9 +185,6 @@ class perform_site_check(): elif is_source: stripped_text_from_html = html_content - # Re #340 - return the content before the 'ignore text' was applied - text_content_before_ignored_filter = stripped_text_from_html.encode('utf-8') - # Re #340 - return the content before the 'ignore text' was applied text_content_before_ignored_filter = stripped_text_from_html.encode('utf-8') diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index 2be62d33..d09f144a 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -185,6 +185,12 @@ class model(dict): def save_history_text(self, contents, timestamp): self.ensure_data_dir_exists() + + # 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 + if self.__newest_history_key and int(timestamp) == int(self.__newest_history_key): + time.sleep(timestamp - self.__newest_history_key) + snapshot_fname = "{}.txt".format(str(uuid.uuid4())) # in /diff/ and /preview/ we are going to assume for now that it's UTF-8 when reading diff --git a/changedetectionio/tests/test_backend.py b/changedetectionio/tests/test_backend.py index 151c0e08..d0cd6b09 100644 --- a/changedetectionio/tests/test_backend.py +++ b/changedetectionio/tests/test_backend.py @@ -3,7 +3,7 @@ import time from flask import url_for from urllib.request import urlopen -from .util import set_original_response, set_modified_response, live_server_setup +from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks sleep_time_for_fetch_thread = 3 @@ -36,7 +36,7 @@ def test_check_basic_change_detection_functionality(client, live_server): client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # It should report nothing found (no new 'unviewed' class) res = client.get(url_for("index")) @@ -69,7 +69,7 @@ def test_check_basic_change_detection_functionality(client, live_server): res = client.get(url_for("form_watch_checknow"), follow_redirects=True) assert b'1 watches are queued for rechecking.' in res.data - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Now something should be ready, indicated by having a 'unviewed' class res = client.get(url_for("index")) @@ -98,14 +98,14 @@ def test_check_basic_change_detection_functionality(client, live_server): assert b'which has this one new line' in res.data assert b'Which is across multiple lines' not in res.data - time.sleep(2) + wait_for_all_checks(client) # Do this a few times.. ensures we dont accidently set the status for n in range(2): client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # It should report nothing found (no new 'unviewed' class) res = client.get(url_for("index")) @@ -125,7 +125,7 @@ def test_check_basic_change_detection_functionality(client, live_server): ) client.get(url_for("form_watch_checknow"), follow_redirects=True) - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) res = client.get(url_for("index")) assert b'unviewed' in res.data diff --git a/changedetectionio/tests/util.py b/changedetectionio/tests/util.py index b943a606..39ee4166 100644 --- a/changedetectionio/tests/util.py +++ b/changedetectionio/tests/util.py @@ -86,6 +86,7 @@ def extract_UUID_from_client(client): def wait_for_all_checks(client): # Loop waiting until done.. attempt=0 + time.sleep(0.1) while attempt < 60: time.sleep(1) res = client.get(url_for("index"))