]> granicus.if.org Git - icinga2/commitdiff
Don't look up joined objects when we don't need to
authorGunnar Beutner <gunnar@beutner.name>
Wed, 14 Oct 2015 13:36:59 +0000 (15:36 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 14 Oct 2015 13:36:59 +0000 (15:36 +0200)
refs #10360

lib/remote/objectqueryhandler.cpp

index 7b1182f8abbdc656bee0cd6d3a67991fb824b79f..d8565acc4bbf293ee323ff3e6c5ec2dd903d7c10 100644 (file)
@@ -49,17 +49,43 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
        qd.Types.insert(type->GetName());
        qd.Permission = "objects/query/" + type->GetName();
 
+       Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
+
+       std::set<String> userJoinAttrs;
+       std::set<String> attrs;
+       Array::Ptr uattrs = params->Get("attrs");
+
+       if (uattrs) {
+               ObjectLock olock(uattrs);
+               BOOST_FOREACH(const String& uattr, uattrs) {
+                       attrs.insert(uattr);
+
+                       String::SizeType dpos = uattr.FindFirstOf(".");
+                       if (dpos != String::NPos) {
+                               String userJoinAttr = uattr.SubStr(0, dpos);
+
+                               if (userJoinAttr == type->GetName().ToLower())
+                                       userJoinAttr = "";
+
+                               userJoinAttrs.insert(userJoinAttr);
+                       }
+               }
+       }
+
        std::vector<String> joinAttrs;
        joinAttrs.push_back("");
 
        for (int fid = 0; fid < type->GetFieldCount(); fid++) {
                Field field = type->GetFieldInfo(fid);
 
-               if (field.Attributes & FANavigation)
-                       joinAttrs.push_back(field.Name);
-       }
+               if (!(field.Attributes & FANavigation))
+                       continue;
 
-       Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
+               if (!userJoinAttrs.empty() && userJoinAttrs.find(field.Name) == userJoinAttrs.end())
+                       continue;
+
+               joinAttrs.push_back(field.Name);
+       }
 
        params->Set("type", type->GetName());
 
@@ -73,16 +99,6 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
 
        Array::Ptr results = new Array();
 
-       std::set<String> attrs;
-       Array::Ptr uattrs = params->Get("attrs");
-
-       if (uattrs) {
-               ObjectLock olock(uattrs);
-               BOOST_FOREACH(const String& uattr, uattrs) {
-                       attrs.insert(uattr);
-               }
-       }
-
        BOOST_FOREACH(const ConfigObject::Ptr& obj, objs) {
                Dictionary::Ptr result1 = new Dictionary();
                results->Add(result1);