From d0e708cba240bd92a4467495caeb654eff6ae69a Mon Sep 17 00:00:00 2001 From: David Kupka Date: Tue, 21 Jun 2016 14:38:00 +0200 Subject: 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 --- ipaserver/plugins/schema.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'ipaserver/plugins') 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', []): -- cgit