diff options
author | David Kupka <dkupka@redhat.com> | 2016-08-09 17:05:17 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-08-17 14:16:04 +0200 |
commit | 6716aaedc87964d7ddd510b12017216b63b1636c (patch) | |
tree | a0fa9a79d6d6189ff795140d92e83024a20a7387 /ipaclient | |
parent | 83b46238e78af8d6d942119c4f6f55b8f508e1f4 (diff) | |
download | freeipa-6716aaedc87964d7ddd510b12017216b63b1636c.tar.gz freeipa-6716aaedc87964d7ddd510b12017216b63b1636c.tar.xz freeipa-6716aaedc87964d7ddd510b12017216b63b1636c.zip |
schema cache: Read server info only once
Do not open/close the file with every access to plugins. Extensive
access to filesystem may cause significant slowdown.
https://fedorahosted.org/freeipa/ticket/6048
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipaclient')
-rw-r--r-- | ipaclient/remote_plugins/__init__.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/ipaclient/remote_plugins/__init__.py b/ipaclient/remote_plugins/__init__.py index 976d69687..2be9222be 100644 --- a/ipaclient/remote_plugins/__init__.py +++ b/ipaclient/remote_plugins/__init__.py @@ -32,6 +32,9 @@ class ServerInfo(collections.MutableMapping): return self def __exit__(self, *_exc_info): + self.flush() + + def flush(self): if self._dirty: self._write() @@ -78,15 +81,21 @@ def get_package(api): if api.env.in_tree: from ipaserver import plugins else: - with ServerInfo(api) as server_info: - client = rpcclient(api) - client.finalize() - try: - plugins = schema.get_package(api, server_info, client) - except schema.NotAvailable: - plugins = compat.get_package(api, server_info, client) - finally: - if client.isconnected(): - client.disconnect() + client = rpcclient(api) + client.finalize() + + try: + server_info = api._server_info + except AttributeError: + server_info = api._server_info = ServerInfo(api) + + try: + plugins = schema.get_package(api, server_info, client) + except schema.NotAvailable: + plugins = compat.get_package(api, server_info, client) + finally: + server_info.flush() + if client.isconnected(): + client.disconnect() return plugins |