mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 23:23:27 +02:00
Speed up metadata reading
Total time for `fdroid readmeta` went down from ~1.6s to ~1.4s on my machine.
This commit is contained in:
parent
528e45d22b
commit
b9ac6fb69a
@ -298,7 +298,7 @@ class Build():
|
|||||||
f = 'vercode'
|
f = 'vercode'
|
||||||
if f not in build_flags:
|
if f not in build_flags:
|
||||||
raise MetaDataException('Unrecognised build flag: ' + f)
|
raise MetaDataException('Unrecognised build flag: ' + f)
|
||||||
setattr(self, f, v)
|
self.__dict__[f] = v
|
||||||
|
|
||||||
def append_flag(self, f, v):
|
def append_flag(self, f, v):
|
||||||
if f not in build_flags:
|
if f not in build_flags:
|
||||||
@ -329,16 +329,20 @@ class Build():
|
|||||||
for f, v in d.iteritems():
|
for f, v in d.iteritems():
|
||||||
self.set_flag(f, v)
|
self.set_flag(f, v)
|
||||||
|
|
||||||
|
list_flags = set(['extlibs', 'srclibs', 'patch', 'rm', 'buildjni', 'preassemble',
|
||||||
|
'update', 'scanignore', 'scandelete', 'gradle', 'antcommands',
|
||||||
|
'gradleprops'])
|
||||||
|
script_flags = set(['init', 'prebuild', 'build'])
|
||||||
|
bool_flags = set(['submodules', 'oldsdkloc', 'forceversion', 'forcevercode',
|
||||||
|
'novcheck'])
|
||||||
|
|
||||||
|
|
||||||
def flagtype(name):
|
def flagtype(name):
|
||||||
if name in ['extlibs', 'srclibs', 'patch', 'rm', 'buildjni', 'preassemble',
|
if name in list_flags:
|
||||||
'update', 'scanignore', 'scandelete', 'gradle', 'antcommands',
|
|
||||||
'gradleprops']:
|
|
||||||
return 'list'
|
return 'list'
|
||||||
if name in ['init', 'prebuild', 'build']:
|
if name in script_flags:
|
||||||
return 'script'
|
return 'script'
|
||||||
if name in ['submodules', 'oldsdkloc', 'forceversion', 'forcevercode',
|
if name in bool_flags:
|
||||||
'novcheck']:
|
|
||||||
return 'bool'
|
return 'bool'
|
||||||
return 'string'
|
return 'string'
|
||||||
|
|
||||||
@ -786,32 +790,31 @@ def sorted_builds(builds):
|
|||||||
esc_newlines = re.compile('\\\\( |\\n)')
|
esc_newlines = re.compile('\\\\( |\\n)')
|
||||||
|
|
||||||
|
|
||||||
|
# This function uses __dict__ to be faster
|
||||||
def post_metadata_parse(app):
|
def post_metadata_parse(app):
|
||||||
|
|
||||||
for f in app_fields:
|
for k, v in app.__dict__.iteritems():
|
||||||
v = app.get_field(f)
|
|
||||||
if type(v) in (float, int):
|
if type(v) in (float, int):
|
||||||
app.set_field(f, str(v))
|
app.__dict__[f] = str(v)
|
||||||
|
|
||||||
for build in app.builds:
|
for build in app.builds:
|
||||||
for k in build_flags:
|
for k, v in app.__dict__.iteritems():
|
||||||
v = build.get_flag(k)
|
|
||||||
|
|
||||||
if type(v) in (float, int):
|
if type(v) in (float, int):
|
||||||
build.set_flag(k, str(v))
|
build.__dict__[k] = str(v)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ftype = flagtype(k)
|
ftype = flagtype(k)
|
||||||
|
|
||||||
if ftype == 'script':
|
if ftype == 'script':
|
||||||
build.set_flag(k, re.sub(esc_newlines, '', v).lstrip().rstrip())
|
build.__dict__[k] = re.sub(esc_newlines, '', v).lstrip().rstrip()
|
||||||
elif ftype == 'bool':
|
elif ftype == 'bool':
|
||||||
# TODO handle this using <xsd:element type="xsd:boolean> in a schema
|
# TODO handle this using <xsd:element type="xsd:boolean> in a schema
|
||||||
if isinstance(v, basestring) and v == 'true':
|
if isinstance(v, basestring) and v == 'true':
|
||||||
build.set_flag(k, True)
|
build.__dict__[k] = True
|
||||||
elif ftype == 'string':
|
elif ftype == 'string':
|
||||||
if isinstance(v, bool) and v:
|
if isinstance(v, bool) and v:
|
||||||
build.set_flag(k, 'yes')
|
build.__dict__[k] = 'yes'
|
||||||
|
|
||||||
# convert to the odd internal format
|
# convert to the odd internal format
|
||||||
for f in ('Description', 'Maintainer Notes'):
|
for f in ('Description', 'Maintainer Notes'):
|
||||||
|
Loading…
Reference in New Issue
Block a user