403b09
From 0ae77ea176190307ef74598179fc8be83169628a Mon Sep 17 00:00:00 2001
403b09
From: David Kupka <dkupka@redhat.com>
403b09
Date: Wed, 20 Jul 2016 13:24:03 +0200
403b09
Subject: [PATCH] help: Do not create instances to get information about
403b09
 commands and topics
403b09
403b09
Creating instance requires that complete schema for the command is
403b09
read from schema cache and passed to constructor. This operation takes
403b09
a lot of time. Utilizing class properties and pregenerated help bits
403b09
allows to get the necessary information directly from classes reducing
403b09
time it takes significantly.
403b09
403b09
https://fedorahosted.org/freeipa/ticket/6048
403b09
403b09
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
403b09
---
403b09
 ipalib/cli.py      | 15 ++++++++-------
403b09
 ipalib/plugable.py |  7 +++++--
403b09
 2 files changed, 13 insertions(+), 9 deletions(-)
403b09
403b09
diff --git a/ipalib/cli.py b/ipalib/cli.py
403b09
index 1faf8285c47d950d5fd311154b6936c8371d746c..d89a5320853ecf575c7ba710b2db2e62e1003141 100644
403b09
--- a/ipalib/cli.py
403b09
+++ b/ipalib/cli.py
403b09
@@ -727,8 +727,8 @@ class help(frontend.Local):
403b09
         self._builtins = []
403b09
 
403b09
         # build help topics
403b09
-        for c in self.api.Command():
403b09
-            if c is not self.api.Command[c.name]:
403b09
+        for c in self.api.Command:
403b09
+            if c is not self.api.Command.get_plugin(c.name):
403b09
                 continue
403b09
             if c.NO_CLI:
403b09
                 continue
403b09
@@ -793,13 +793,14 @@ class help(frontend.Local):
403b09
             self.print_commands(name, outfile)
403b09
         elif name == "commands":
403b09
             mcl = 0
403b09
-            for cmd in self.Command():
403b09
-                if cmd is not self.Command[cmd.name]:
403b09
+            for cmd_plugin in self.Command:
403b09
+                if cmd_plugin is not self.Command.get_plugin(cmd_plugin.name):
403b09
                     continue
403b09
-                if cmd.NO_CLI:
403b09
+                if cmd_plugin.NO_CLI:
403b09
                     continue
403b09
-                mcl = max(mcl, len(cmd.name))
403b09
-                writer('%s  %s' % (to_cli(cmd.name).ljust(mcl), cmd.summary))
403b09
+                mcl = max(mcl, len(cmd_plugin.name))
403b09
+                writer('%s  %s' % (to_cli(cmd_plugin.name).ljust(mcl),
403b09
+                                   cmd_plugin.summary))
403b09
         else:
403b09
             raise HelpError(topic=name)
403b09
 
403b09
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
403b09
index 073ad05d7aee5e83cae5c6e20bac8f9439505198..af35f5bae27a17230267d5b10b5fdc4f784a4760 100644
403b09
--- a/ipalib/plugable.py
403b09
+++ b/ipalib/plugable.py
403b09
@@ -318,9 +318,12 @@ class APINameSpace(collections.Mapping):
403b09
         self.__enumerate()
403b09
         return iter(self.__plugins)
403b09
 
403b09
-    def __getitem__(self, key):
403b09
+    def get_plugin(self, key):
403b09
         self.__enumerate()
403b09
-        plugin = self.__plugins_by_key[key]
403b09
+        return self.__plugins_by_key[key]
403b09
+
403b09
+    def __getitem__(self, key):
403b09
+        plugin = self.get_plugin(key)
403b09
         return self.__api._get(plugin)
403b09
 
403b09
     def __call__(self):
403b09
-- 
403b09
2.7.4
403b09