diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 60c7e0f1..cc60f311 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -298,7 +298,7 @@ def changedetection_app(config=None, datastore_o=None): # Sort by last_changed and add the uuid which is usually the key.. sorted_watches = [] - # @todo needs a .itemsWithTag() or something + # @todo needs a .itemsWithTag() or something - then we can use that in Jinaj2 and throw this away for uuid, watch in datastore.data['watching'].items(): if limit_tag != None: @@ -403,8 +403,6 @@ def changedetection_app(config=None, datastore_o=None): watch['uuid'] = uuid sorted_watches.append(watch) - sorted_watches.sort(key=lambda x: x['last_changed'], reverse=True) - existing_tags = datastore.get_all_tags() form = forms.quickWatchForm(request.form) diff --git a/changedetectionio/fetch_site_status.py b/changedetectionio/fetch_site_status.py index b5eef3ab..2ddf5ca3 100644 --- a/changedetectionio/fetch_site_status.py +++ b/changedetectionio/fetch_site_status.py @@ -255,9 +255,6 @@ class perform_site_check(): # Looks like something changed, but did it match all the rules? if blocked: changed_detected = False - else: - update_obj["last_changed"] = timestamp - # Extract title as title if is_html: diff --git a/changedetectionio/store.py b/changedetectionio/store.py index fca06438..d506aa92 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -518,3 +518,11 @@ class ChangeDetectionStore: # But we should set it back to a empty dict so we don't break if this schema runs on an earlier version. # In the distant future we can remove this entirely self.data['watching'][uuid]['history'] = {} + + # We incorrectly stored last_changed when there was not a change, and then confused the output list table + def update_3(self): + for uuid, watch in self.data['watching'].items(): + # Be sure it's recalculated + p = watch.history + if watch.history_n < 2: + watch['last_changed'] = 0 diff --git a/changedetectionio/templates/watch-overview.html b/changedetectionio/templates/watch-overview.html index b247fc7a..17b14904 100644 --- a/changedetectionio/templates/watch-overview.html +++ b/changedetectionio/templates/watch-overview.html @@ -40,7 +40,7 @@ - {% for watch in watches %} + {% for watch in watches|sort(attribute='last_changed', reverse=True) %} {{watch|format_last_checked_time|safe}} - {% if watch.history_n >=2 and watch.last_changed %} + {% if watch.history_n >=2 and watch.last_changed >0 %} {{watch.last_changed|format_timestamp_timeago}} {% else %} Not yet diff --git a/changedetectionio/tests/test_api.py b/changedetectionio/tests/test_api.py index 5f982b69..dd66012e 100644 --- a/changedetectionio/tests/test_api.py +++ b/changedetectionio/tests/test_api.py @@ -95,6 +95,8 @@ def test_api_simple(client, live_server): assert watch_uuid in json.loads(res.data).keys() before_recheck_info = json.loads(res.data)[watch_uuid] assert before_recheck_info['last_checked'] != 0 + #705 `last_changed` should be zero on the first check + assert before_recheck_info['last_changed'] == 0 assert before_recheck_info['title'] == 'My test URL' set_modified_response() diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index bda34fef..7202142d 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -98,7 +98,9 @@ class update_worker(threading.Thread): # Notifications should only trigger on the second time (first time, we gather the initial snapshot) if watch.history_n >= 2: - print(">> Change detected in UUID {} - {}".format(uuid, watch['url'])) + # Atleast 2, means there really was a change + self.datastore.update_watch(uuid=uuid, update_obj={'last_changed': round(now)}) + watch_history = watch.history dates = list(watch_history.keys()) # Theoretically it's possible that this could be just 1 long, @@ -109,7 +111,6 @@ class update_worker(threading.Thread): ) prev_fname = watch_history[dates[-2]] - # Did it have any notification alerts to hit? if len(watch['notification_urls']): print(">>> Notifications queued for UUID from watch {}".format(uuid)) @@ -157,6 +158,7 @@ class update_worker(threading.Thread): # Always record that we atleast tried self.datastore.update_watch(uuid=uuid, update_obj={'fetch_time': round(time.time() - now, 3), 'last_checked': round(time.time())}) + # Always save the screenshot if it's available if screenshot: self.datastore.save_screenshot(watch_uuid=uuid, screenshot=screenshot)