diff options
author | David Kupka <dkupka@redhat.com> | 2016-06-21 14:38:00 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-06-21 15:11:19 +0200 |
commit | d0e708cba240bd92a4467495caeb654eff6ae69a (patch) | |
tree | 93d7378bdbe439074c66f0419fdce05ed5cbfa5b /ipaserver/plugins | |
parent | 4b97cabb52585e9f58a2f2034ba71fd7e8d678d7 (diff) | |
download | freeipa-d0e708cba240bd92a4467495caeb654eff6ae69a.tar.gz freeipa-d0e708cba240bd92a4467495caeb654eff6ae69a.tar.xz freeipa-d0e708cba240bd92a4467495caeb654eff6ae69a.zip |
schema: Cache schema in api instance
To avoid generating schema for every schema command call store schema in
api instance when first generated and reuse it in next calls.
https://fedorahosted.org/freeipa/ticket/4739
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipaserver/plugins')
-rw-r--r-- | ipaserver/plugins/schema.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/ipaserver/plugins/schema.py b/ipaserver/plugins/schema.py index d6cf31f9a..df3bff1d0 100644 --- a/ipaserver/plugins/schema.py +++ b/ipaserver/plugins/schema.py @@ -729,7 +729,7 @@ class schema(Command): return fingerprint.hexdigest()[:8] - def execute(self, *args, **kwargs): + def _generate_schema(self, **kwargs): commands = list(self.api.Object.command.search(**kwargs)) for command in commands: name = command['name'] @@ -750,9 +750,17 @@ class schema(Command): schema['commands'] = commands schema['classes'] = classes schema['topics'] = topics + schema['fingerprint'] = self._calculate_fingerprint(schema) + + return schema + + def execute(self, *args, **kwargs): + try: + schema = self.api._schema + except AttributeError: + schema = self._generate_schema(**kwargs) + setattr(self.api, '_schema', schema) - schema_fp = self._calculate_fingerprint(schema) - schema['fingerprint'] = schema_fp schema['ttl'] = SCHEMA_TTL if schema['fingerprint'] in kwargs.get('known_fingerprints', []): |