From 8ae99065c194f8269cf1f77314f4e2da65aa9163 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcritten@redhat.com>
Date: Wed, 30 Mar 2011 10:20:40 -0400
Subject: [PATCH] Cache the value of get_ipa_config() in the request context.

There are some operations that fetch the configuration multiple times.
This will return a cached value instead of getting it from LDAP over
and over.

ticket 1023
---
 ipaserver/plugins/ldap2.py |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py
index ebbca60..6a71c5d 100644
--- a/ipaserver/plugins/ldap2.py
+++ b/ipaserver/plugins/ldap2.py
@@ -633,6 +633,12 @@ class ldap2(CrudBackend, Encoder):
         """Returns the IPA configuration entry (dn, entry_attrs)."""
         cdn = "%s,%s" % (api.Object.config.get_dn(), api.env.basedn)
         try:
+            config_entry = getattr(context, 'config_entry')
+            return (cdn, config_entry)
+        except AttributeError:
+            # Not in our context yet
+            pass
+        try:
             (cdn, config_entry) = self.find_entries(
                 None, attrs_list, base_dn=cdn, scope=self.SCOPE_BASE,
                 time_limit=2, size_limit=10
@@ -642,6 +648,7 @@ class ldap2(CrudBackend, Encoder):
         for a in self.config_defaults:
             if a not in config_entry:
                 config_entry[a] = self.config_defaults[a]
+        setattr(context, 'config_entry', config_entry)
         return (cdn, config_entry)
 
     def get_schema(self):
-- 
1.7.4

