From 889ec6e491c5c5c298ff9d3681b55c41e5ad5d3c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 28 Feb 2017 10:35:39 +0530 Subject: [PATCH] Implement update interval for downloading metadata source plugins --- src/calibre/ebooks/metadata/sources/update.py | 5 ++--- src/calibre/utils/config.py | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/update.py b/src/calibre/ebooks/metadata/sources/update.py index 7ef06e6ecc..52355c52af 100644 --- a/src/calibre/ebooks/metadata/sources/update.py +++ b/src/calibre/ebooks/metadata/sources/update.py @@ -57,6 +57,8 @@ def update_plugin(name): def main(report_error, report_action=prints): try: + if time.time() - cache.mtime() < UPDATE_INTERVAL: + return try: report_action('Fetching metadata source hashes...') needed = update_needed() @@ -78,9 +80,6 @@ def main(report_error, report_action=prints): def update_sources(wait_for_completion=False): if update_sources.worker is not None: return False - epoch = cache.get('last_update', 0) - if time.time() - epoch < UPDATE_INTERVAL: - return False update_sources.errors = errs = [] update_sources.worker = t = Thread( target=main, args=(errs.append, debug_print), name='MSourcesUpdater') diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py index 4463ec5f31..ce69cd56c8 100644 --- a/src/calibre/utils/config.py +++ b/src/calibre/utils/config.py @@ -286,6 +286,12 @@ class XMLConfig(dict): self.refresh() + def mtime(self): + try: + return os.path.getmtime(self.file_path) + except EnvironmentError: + return 0 + def raw_to_object(self, raw): return plistlib.readPlistFromString(raw)