On 16.11.2015 20:18, Rob Crittenden wrote:
Martin Basti wrote:


On 16.11.2015 18:57, Martin Basti wrote:
How does this code work (IMO it doesn't), ldap2.py

    def find_entries(self, filter=None, attrs_list=None, base_dn=None,
                     scope=_ldap.SCOPE_SUBTREE, time_limit=None,
                     size_limit=None, search_refs=False,
paged_search=False):

        def _get_limits():
            """Get configured global limits, caching them for more
calls"""
            if not _lims:
                config = self.get_ipa_config()
                _lims['time'] = int(config.get('ipasearchtimelimit',
[None])[0])
                _lims['size'] =
int(config.get('ipasearchrecordslimit', [None])[0])
            return _lims
        _lims = {}

        if time_limit is None:
            time_limit = _get_limits()['time']
        if size_limit is None:
            size_limit = _get_limits()['size']

Code above is supposed to do caching, but it doesn't do it. This might
work if _lims were self._lims.
I tried similar code to test this behavior:

class test:
    def __init__(self):
       pass

    def cached_call(self):
       """configured global limits"""
       _lims = {}
       def _get_limits():
           if not _lims:
               _lims['t']='oujeee'
               print 'getting limits'
           return _lims

       print "Limits:", _get_limits()['t']

t = test()
t.cached_call()
t.cached_call()
t.cached_call()
t.cached_call()

Output:
$ python testcaching.py
Limits: getting limits
oujeee
Limits: getting limits
oujeee
Limits: getting limits
oujeee
Limits: getting limits
oujeee

So it does not do caching, or am I wrong?
Martin^2

That code works, the whole caching is just for the second call of
_get_limits()

Can we instead just caching limits for second use, do caching for whole
connection?
This may be effective for methods/commands that calls search and show
several times.

Is there something that prevents us to do that?


It already is cached. See get_ipa_config().

rob
I missed that part there, thank you.
Martin

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to