From da0a627ac073048a6127d11889bf2743b6639089 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Wed, 29 Jun 2022 18:39:54 +0000 Subject: [PATCH] improve and speed up content.json loading parse json (which is required anyway) instead of ad-hock re-based parsing --- src/Content/ContentManager.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Content/ContentManager.py b/src/Content/ContentManager.py index 27da402b..0c0f27a7 100644 --- a/src/Content/ContentManager.py +++ b/src/Content/ContentManager.py @@ -78,19 +78,19 @@ class ContentManager(object): if os.path.isfile(content_path): try: + new_content = self.site.storage.loadJson(content_inner_path) # Check if file is newer than what we have if not force and old_content and not self.site.settings.get("own"): - for line in open(content_path): - if '"modified"' not in line: - continue - match = re.search(r"([0-9\.]+),$", line.strip(" \r\n")) - if match and float(match.group(1)) <= old_content.get("modified", 0): - self.log.debug("%s loadContent same json file, skipping" % content_inner_path) - return [], [] - - new_content = self.site.storage.loadJson(content_inner_path) + new_ts = int(float(new_content.get('modified', 0))) + old_ts = int(float(old_content.get('modified', 0))) + if new_ts < old_ts: + self.log.debug('got older version of {content_inner_path} ({new_ts} < {old_ts}), ignoring') + return [], [] + elif new_ts == old_ts: + self.log.debug('got same timestamp version of {content_inner_path} ({new_ts}), ignoring') + return [], [] except Exception as err: - self.log.warning("%s load error: %s" % (content_path, Debug.formatException(err))) + self.log.warning(f'{content_path} load error: {Debug.formatException(err)}') return [], [] else: self.log.debug("Content.json not exist: %s" % content_path)