pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone
Blob Blame History Raw
From 6959578fdbdfd38113b26cd9e4f94b298343a6f0 Mon Sep 17 00:00:00 2001
From: David Kupka <dkupka@redhat.com>
Date: Tue, 9 Aug 2016 17:05:17 +0200
Subject: [PATCH] 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>
---
 ipaclient/remote_plugins/schema.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index c72109ac3bb9b7a71f9cbc056eaf3a4d8371d035..aadc891750782b0961bc46989e3693d1d3ed0ecb 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -378,6 +378,9 @@ class ServerInfo(collections.MutableMapping):
         return self
 
     def __exit__(self, *_exc_info):
+        self.flush()
+
+    def flush(self):
         if self._dirty:
             self._write()
 
@@ -603,9 +606,16 @@ def get_package(api, client):
     try:
         schema = api._schema
     except AttributeError:
-        with ServerInfo(api.env.hostname) as server_info:
+        try:
+            server_info = api._server_info
+        except AttributeError:
+            server_info = api._server_info = ServerInfo(api)
+
+        try:
             schema = Schema(api, server_info, client)
             object.__setattr__(api, '_schema', schema)
+        finally:
+            server_info.flush()
 
     fingerprint = str(schema['fingerprint'])
     package_name = '{}${}'.format(__name__, fingerprint)
-- 
2.7.4