Even if ACKed, don't push this patch alone. It is part of some work that Petr V is going to be doing as part of fixing https://fedorahosted.org/freeipa/ticket/1933.


From b5b93109a9035557770f0959e21f4310bac5b7ba Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Thu, 6 Oct 2011 16:38:01 -0400
Subject: [PATCH] split metadata call

The JSON metadata call has grown large enough that parsing it requires too much stack space on some browsers.  TO avoid breaking the API, this change reuses some testing parameters that we established for the metadata call in the past.  To fetch just the objects call it like this:
{"method":"json_metadata","params":[["all",""],{}],"id":0}
And just the methods call it like this:
{"method":"json_metadata","params":[["","all"],{}],"id":0}

Note the difference in the positional parameters.

To get a specific object,  pass the object name as the first parameter.  To get a specific method, pass a blank first parameter and the method name in the second parameter.

THis is not ideal, but we are constrained by the existing API.
---
 ipalib/plugins/internal.py |   32 ++++++++++++++++++--------------
 1 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index ce6f2548965846eb1f28ccf1814902958b4f5a26..8c5b0955b1c2e2c1c0c2b15c0e026e24f9b3eefe 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -54,25 +54,29 @@ class json_metadata(Command):
     )
 
     def execute(self, objname, methodname):
+        objects = dict()
+        methods = dict()
 
-        if objname and objname in self.api.Object:
-
-            objects = dict(
-                (objname, json_serialize(self.api.Object[objname]))
-            )
-
+        if objname :
+            if objname in self.api.Object:
+                o = self.api.Object[objname]
+                objects = dict([(o.name, json_serialize(o))])
+            elif objname == "all":
+                objects = dict(
+                    (o.name, json_serialize(o)) for o in self.api.Object()
+                )
+        elif methodname:
+            if  methodname in self.api.Method:
+                m = self.api.Method[methodname]
+                methods = dict([(m.name, json_serialize(m))])
+            elif methodname == "all":
+                methods = dict(
+                    (m.name, json_serialize(m)) for m in self.api.Method()
+                )
         else:
             objects = dict(
                 (o.name, json_serialize(o)) for o in self.api.Object()
             )
-
-        if methodname and methodname in self.api.Method:
-
-            methods = dict(
-                (methodname, json_serialize(self.api.Method[methodname]))
-            )
-
-        else:
             methods = dict(
                 (m.name, json_serialize(m)) for m in self.api.Method()
             )
-- 
1.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to