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
|
from .flock import locked
|
||||||
|
|
||||||
data = {TYPE_IMAGE: {}, TYPE_CONTAINER: {}, TYPE_APP: {}}
|
data = {TYPE_IMAGE: {}, TYPE_CONTAINER: {}, TYPE_APP: {}}
|
||||||
mtime = None
|
mtime = 0
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
global data
|
global data
|
||||||
|
@ -67,10 +67,13 @@ 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():
|
||||||
global data
|
global data
|
||||||
if not data:
|
global mtime
|
||||||
|
# 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()
|
||||||
@ -80,6 +83,7 @@ def load():
|
|||||||
packages_sig = resource.content
|
packages_sig = resource.content
|
||||||
PUBLIC_KEY.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
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()
|
||||||
|
@ -35,7 +35,7 @@ def sign_file(file_path):
|
|||||||
return private_key.sign(hasher.finalize(), ec.ECDSA(utils.Prehashed(sha512)))
|
return private_key.sign(hasher.finalize(), ec.ECDSA(utils.Prehashed(sha512)))
|
||||||
|
|
||||||
data = {TYPE_IMAGE: {}, TYPE_APP: {}}
|
data = {TYPE_IMAGE: {}, TYPE_APP: {}}
|
||||||
mtime = None
|
mtime = 0
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
global data
|
global data
|
||||||
|
Loading…
Reference in New Issue
Block a user