Cache online_repo listing for 10 seconds

This commit is contained in:
Disassembler 2020-03-29 15:22:38 +02:00
parent 7cf9a10b46
commit b434e6af92
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
3 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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()

View File

@ -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