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>
This commit is contained in:
David Kupka 2016-08-09 17:05:17 +02:00 committed by Jan Cholasta
parent 83b46238e7
commit 6716aaedc8

View File

@ -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