The Identity, Policy and Audit system
CentOS Sources
2016-11-03 403b09ab980c02ef36095973349a13e0181c794a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From 0ae77ea176190307ef74598179fc8be83169628a Mon Sep 17 00:00:00 2001
From: David Kupka <dkupka@redhat.com>
Date: Wed, 20 Jul 2016 13:24:03 +0200
Subject: [PATCH] help: Do not create instances to get information about
 commands and topics
 
Creating instance requires that complete schema for the command is
read from schema cache and passed to constructor. This operation takes
a lot of time. Utilizing class properties and pregenerated help bits
allows to get the necessary information directly from classes reducing
time it takes significantly.
 
https://fedorahosted.org/freeipa/ticket/6048
 
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
---
 ipalib/cli.py      | 15 ++++++++-------
 ipalib/plugable.py |  7 +++++--
 2 files changed, 13 insertions(+), 9 deletions(-)
 
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 1faf8285c47d950d5fd311154b6936c8371d746c..d89a5320853ecf575c7ba710b2db2e62e1003141 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -727,8 +727,8 @@ class help(frontend.Local):
         self._builtins = []
 
         # build help topics
-        for c in self.api.Command():
-            if c is not self.api.Command[c.name]:
+        for c in self.api.Command:
+            if c is not self.api.Command.get_plugin(c.name):
                 continue
             if c.NO_CLI:
                 continue
@@ -793,13 +793,14 @@ class help(frontend.Local):
             self.print_commands(name, outfile)
         elif name == "commands":
             mcl = 0
-            for cmd in self.Command():
-                if cmd is not self.Command[cmd.name]:
+            for cmd_plugin in self.Command:
+                if cmd_plugin is not self.Command.get_plugin(cmd_plugin.name):
                     continue
-                if cmd.NO_CLI:
+                if cmd_plugin.NO_CLI:
                     continue
-                mcl = max(mcl, len(cmd.name))
-                writer('%s  %s' % (to_cli(cmd.name).ljust(mcl), cmd.summary))
+                mcl = max(mcl, len(cmd_plugin.name))
+                writer('%s  %s' % (to_cli(cmd_plugin.name).ljust(mcl),
+                                   cmd_plugin.summary))
         else:
             raise HelpError(topic=name)
 
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 073ad05d7aee5e83cae5c6e20bac8f9439505198..af35f5bae27a17230267d5b10b5fdc4f784a4760 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -318,9 +318,12 @@ class APINameSpace(collections.Mapping):
         self.__enumerate()
         return iter(self.__plugins)
 
-    def __getitem__(self, key):
+    def get_plugin(self, key):
         self.__enumerate()
-        plugin = self.__plugins_by_key[key]
+        return self.__plugins_by_key[key]
+
+    def __getitem__(self, key):
+        plugin = self.get_plugin(key)
         return self.__api._get(plugin)
 
     def __call__(self):
-- 
2.7.4