Cache online_repo listing for 10 seconds
This commit is contained in:
parent
7cf9a10b46
commit
b434e6af92
@ -9,7 +9,7 @@ from .config import REPO_FILE, REPO_LOCK_FILE, TYPE_APP, TYPE_CONTAINER, TYPE_IM
|
||||
from .flock import locked
|
||||
|
||||
data = {TYPE_IMAGE: {}, TYPE_CONTAINER: {}, TYPE_APP: {}}
|
||||
mtime = None
|
||||
mtime = 0
|
||||
|
||||
def load():
|
||||
global data
|
||||
|
@ -67,10 +67,13 @@ def unpack_archive(archive_path, destination, expected_hash, observer):
|
||||
os.unlink(archive_path)
|
||||
|
||||
data = None
|
||||
mtime = 0
|
||||
|
||||
def load():
|
||||
global data
|
||||
if not data:
|
||||
global mtime
|
||||
# Cache the result for 10 seconds
|
||||
if mtime < time.time()-10:
|
||||
with requests.Session() as session:
|
||||
resource = session.get(ONLINE_REPO_URL, timeout=5)
|
||||
resource.raise_for_status()
|
||||
@ -80,6 +83,7 @@ def load():
|
||||
packages_sig = resource.content
|
||||
PUBLIC_KEY.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
||||
data = json.loads(packages.decode())
|
||||
mtime = time.time()
|
||||
|
||||
def get_entries(entry_type):
|
||||
load()
|
||||
|
@ -35,7 +35,7 @@ def sign_file(file_path):
|
||||
return private_key.sign(hasher.finalize(), ec.ECDSA(utils.Prehashed(sha512)))
|
||||
|
||||
data = {TYPE_IMAGE: {}, TYPE_APP: {}}
|
||||
mtime = None
|
||||
mtime = 0
|
||||
|
||||
def load():
|
||||
global data
|
||||
|
Loading…
Reference in New Issue
Block a user