pmb.parse.apkindex.parse(): Use caching

Big speed improvement for buildinfo.json files, down from 30-60s to 1-5s.
This commit is contained in:
Oliver Smith 2017-06-18 01:09:21 +02:00
parent af8c9fcf5b
commit ce147b0381
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
2 changed files with 15 additions and 0 deletions

View File

@ -170,6 +170,15 @@ def parse(args, path, strict=False):
}, ...
}
"""
# Try to get a cached result first
lastmod = os.path.getmtime(path)
if path in args.cache["apkindex"]:
cache = args.cache["apkindex"][path]
if cache["lastmod"] == lastmod:
return cache["ret"]
# Parse the whole APKINDEX.tar.gz file
ret = {}
start = [0]
with tarfile.open(path, "r:gz") as tar:
@ -188,6 +197,9 @@ def parse(args, path, strict=False):
if len(split) == 2:
parse_add_block(path, strict, ret, block,
split[0], split[1])
# Update the cache
args.cache["apkindex"][path] = {"lastmod": lastmod, "ret": ret}
return ret

View File

@ -199,6 +199,9 @@ def arguments():
# Add convinience shortcuts
setattr(args, "arch_native", pmb.parse.arch.alpine_native())
# Add a caching dict
setattr(args, "cache", {"apkindex": {}})
# Add and verify the deviceinfo (only after initialization)
if args.action != "init":
setattr(args, "deviceinfo", pmb.parse.deviceinfo(args))