Cache online_repo results indefinitely, but allow force reload

This commit is contained in:
Disassembler 2020-04-03 19:42:06 +02:00
parent 261f237dc7
commit 7dd02f0e2a
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -86,13 +86,10 @@ def unpack_archive(archive_path, destination, expected_hash, observer):
os.unlink(archive_path)
data = None
mtime = 0
def load():
def load(force=False):
global data
global mtime
# Cache the result for 10 seconds
if mtime < time.time()-10:
if not data or force:
with requests.Session() as session:
resource = session.get(ONLINE_REPO_URL, timeout=5)
resource.raise_for_status()
@ -102,7 +99,6 @@ def load():
packages_sig = resource.content
get_public_key().verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
data = json.loads(packages.decode())
mtime = time.time()
def get_entries(entry_type):
load()