summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2017-02-20 20:09:13 +0100
committerMartin Basti <mbasti@redhat.com>2017-03-01 12:50:43 +0100
commit332dbab1ff09eb719eb9e0a7a90bbf5b6e69ddc9 (patch)
tree03d47c7a55497ad51eb51b2fcb223bc5bfb00aed
parentc49320435ddc67210c0d95be273e971ea8ffad6d (diff)
downloadfreeipa-332dbab1ff09eb719eb9e0a7a90bbf5b6e69ddc9.tar.gz
freeipa-332dbab1ff09eb719eb9e0a7a90bbf5b6e69ddc9.tar.xz
freeipa-332dbab1ff09eb719eb9e0a7a90bbf5b6e69ddc9.zip
Speed up client schema cache
It's inefficient to open a zip file over and over again. By loading all members of the schema cache file at once, the ipa CLI script starts about 25 to 30% faster for simple cases like help and ping. Before: $ time for i in {1..20}; do ./ipa ping >/dev/null; done real 0m13.608s user 0m10.316s sys 0m1.121s After: $ time for i in {1..20}; do ./ipa ping >/dev/null; done real 0m9.330s user 0m7.635s sys 0m1.146s https://fedorahosted.org/freeipa/ticket/6690 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: David Kupka <dkupka@redhat.com>
-rw-r--r--ipaclient/remote_plugins/schema.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index 15c03f4af..13bdee4ef 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -458,11 +458,15 @@ class Schema(object):
with self._open(fingerprint, 'rb') as f:
self._file.write(f.read())
+ # It's more efficient to read zip file members at once than to open
+ # the zip file a couple of times, see #6690.
with zipfile.ZipFile(self._file, 'r') as schema:
for name in schema.namelist():
ns, _slash, key = name.partition('/')
if ns in self.namespaces:
- self._dict[ns][key] = None
+ self._dict[ns][key] = schema.read(name)
+ elif name == '_help':
+ self._help = schema.read(name)
def __getitem__(self, key):
try:
@@ -520,16 +524,12 @@ class Schema(object):
f.truncate(0)
f.write(self._file.read())
- def _read(self, path):
- with zipfile.ZipFile(self._file, 'r') as zf:
- return json.loads(zf.read(path).decode('utf-8'))
-
def read_namespace_member(self, namespace, member):
value = self._dict[namespace][member]
- if value is None:
- path = '{}/{}'.format(namespace, member)
- value = self._dict[namespace][member] = self._read(path)
+ if isinstance(value, bytes):
+ value = json.loads(value.decode('utf-8'))
+ self._dict[namespace][member] = value
return value
@@ -537,8 +537,8 @@ class Schema(object):
return iter(self._dict[namespace])
def get_help(self, namespace, member):
- if not self._help:
- self._help = self._read('_help')
+ if isinstance(self._help, bytes):
+ self._help = json.loads(self._help.decode('utf-8'))
return self._help[namespace][member]