diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 617e9874..d503a1fb 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -314,7 +314,7 @@ 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) + sorted_watches.sort(key=lambda x: x.last_changed, reverse=False) fg = FeedGenerator() fg.title('changedetection.io') @@ -333,7 +333,7 @@ def changedetection_app(config=None, datastore_o=None): if not watch.viewed: # Re #239 - GUID needs to be individual for each event # @todo In the future make this a configurable link back (see work on BASE_URL https://github.com/dgtlmoon/changedetection.io/pull/228) - guid = "{}/{}".format(watch['uuid'], watch['last_changed']) + guid = "{}/{}".format(watch['uuid'], watch.last_changed) fe = fg.add_entry() # Include a link to the diff page, they will have to login here to see if password protection is enabled. diff --git a/changedetectionio/api/api_v1.py b/changedetectionio/api/api_v1.py index cec6645d..a432bc67 100644 --- a/changedetectionio/api/api_v1.py +++ b/changedetectionio/api/api_v1.py @@ -113,7 +113,7 @@ class CreateWatch(Resource): list[k] = {'url': v['url'], 'title': v['title'], 'last_checked': v['last_checked'], - 'last_changed': v['last_changed'], + 'last_changed': v.last_changed, 'last_error': v['last_error']} if request.args.get('recheck_all'): diff --git a/changedetectionio/changedetection.py b/changedetectionio/changedetection.py index 34efd850..32c21ac4 100755 --- a/changedetectionio/changedetection.py +++ b/changedetectionio/changedetection.py @@ -50,11 +50,6 @@ def main(): create_datastore_dir = False for opt, arg in opts: - # if opt == '--clear-all-history': - # Remove history, the actual files you need to delete manually. - # for uuid, watch in datastore.data['watching'].items(): - # watch.update({'history': {}, 'last_checked': 0, 'last_changed': 0, 'previous_md5': None}) - if opt == '-s': ssl_mode = True diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index ad1b1b42..50f792b0 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -19,7 +19,6 @@ class model(dict): 'url': None, 'tag': None, 'last_checked': 0, - 'last_changed': 0, 'paused': False, 'last_viewed': 0, # history key value of the last viewed via the [diff] link #'newest_history_key': 0, @@ -59,11 +58,11 @@ class model(dict): jitter_seconds = 0 def __init__(self, *arg, **kw): - import uuid + self.update(self.__base_config) self.__datastore_path = kw['datastore_path'] - self['uuid'] = str(uuid.uuid4()) + self['uuid'] = str(uuid_builder.uuid4()) del kw['datastore_path'] @@ -71,7 +70,10 @@ class model(dict): self.update(kw['default']) del kw['default'] - # goes at the end so we update the default object with the initialiser + # Be sure the cached timestamp is ready + bump = self.history + + # Goes at the end so we update the default object with the initialiser super(model, self).__init__(*arg, **kw) @property @@ -81,6 +83,15 @@ class model(dict): return False + @property + def last_changed(self): + # last_changed will be the newest snapshot, but when we have just one snapshot, it should be 0 + if self.__history_n <= 1: + return 0 + if self.__newest_history_key: + return int(self.__newest_history_key) + return 0 + @property def history_n(self): return self.__history_n diff --git a/changedetectionio/store.py b/changedetectionio/store.py index e91f724c..afcc9cb6 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -254,7 +254,6 @@ class ChangeDetectionStore: self.__data['watching'][uuid].update( {'last_checked': 0, - 'last_changed': 0, 'last_viewed': 0, 'previous_md5': False, 'last_notification_error': False, @@ -528,8 +527,5 @@ class ChangeDetectionStore: # 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 + # see https://github.com/dgtlmoon/changedetection.io/pull/835 + return diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index ccdc5bd7..5596fcb1 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -264,8 +264,6 @@ 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: - # Atleast 2, means there really was a change - self.datastore.update_watch(uuid=uuid, update_obj={'last_changed': round(now)}) if not self.datastore.data['watching'][uuid].get('notification_muted'): self.send_content_changed_notification(self, watch_uuid=uuid)