From 7ace259d70b2708e37e9afad3f3c452ebdbf8eea Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 11 Oct 2023 14:04:12 +0200 Subject: [PATCH] System - No need to run updates on fresh installs (#1854) --- changedetectionio/store.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 3d6e0623..9f376df9 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -96,6 +96,14 @@ class ChangeDetectionStore: self.add_watch(url='https://changedetection.io/CHANGELOG.txt', tag='changedetection.io', extras={'fetch_backend': 'html_requests'}) + + updates_available = self.get_updates_available() + self.__data['settings']['application']['schema_version'] = updates_available.pop() + + else: + # Bump the update version by running updates + self.run_updates() + self.__data['version_tag'] = version_tag # Just to test that proxies.json if it exists, doesnt throw a parsing error on startup @@ -125,9 +133,6 @@ class ChangeDetectionStore: secret = secrets.token_hex(16) self.__data['settings']['application']['api_access_token'] = secret - # Bump the update version by running updates - self.run_updates() - self.needs_write = True # Finally start the thread that will manage periodic data saves to JSON @@ -625,14 +630,8 @@ class ChangeDetectionStore: def tag_exists_by_name(self, tag_name): return any(v.get('title', '').lower() == tag_name.lower() for k, v in self.__data['settings']['application']['tags'].items()) - # Run all updates - # IMPORTANT - Each update could be run even when they have a new install and the schema is correct - # So therefor - each `update_n` should be very careful about checking if it needs to actually run - # Probably we should bump the current update schema version with each tag release version? - def run_updates(self): + def get_updates_available(self): import inspect - import shutil - updates_available = [] for i, o in inspect.getmembers(self, predicate=inspect.ismethod): m = re.search(r'update_(\d+)$', i) @@ -640,6 +639,15 @@ class ChangeDetectionStore: updates_available.append(int(m.group(1))) updates_available.sort() + return updates_available + + # Run all updates + # IMPORTANT - Each update could be run even when they have a new install and the schema is correct + # So therefor - each `update_n` should be very careful about checking if it needs to actually run + # Probably we should bump the current update schema version with each tag release version? + def run_updates(self): + import shutil + updates_available = self.get_updates_available() for update_n in updates_available: if update_n > self.__data['settings']['application']['schema_version']: print ("Applying update_{}".format((update_n)))