Cache online_repo results indefinitely, but allow force reload
This commit is contained in:
parent
261f237dc7
commit
7dd02f0e2a
@ -86,13 +86,10 @@ def unpack_archive(archive_path, destination, expected_hash, observer):
|
|||||||
os.unlink(archive_path)
|
os.unlink(archive_path)
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
mtime = 0
|
|
||||||
|
|
||||||
def load():
|
def load(force=False):
|
||||||
global data
|
global data
|
||||||
global mtime
|
if not data or force:
|
||||||
# Cache the result for 10 seconds
|
|
||||||
if mtime < time.time()-10:
|
|
||||||
with requests.Session() as session:
|
with requests.Session() as session:
|
||||||
resource = session.get(ONLINE_REPO_URL, timeout=5)
|
resource = session.get(ONLINE_REPO_URL, timeout=5)
|
||||||
resource.raise_for_status()
|
resource.raise_for_status()
|
||||||
@ -102,7 +99,6 @@ def load():
|
|||||||
packages_sig = resource.content
|
packages_sig = resource.content
|
||||||
get_public_key().verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
get_public_key().verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
||||||
data = json.loads(packages.decode())
|
data = json.loads(packages.decode())
|
||||||
mtime = time.time()
|
|
||||||
|
|
||||||
def get_entries(entry_type):
|
def get_entries(entry_type):
|
||||||
load()
|
load()
|
||||||
|
Loading…
Reference in New Issue
Block a user