From 48d80e29a0730e72bf045cb98e4c111146e498af Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 14 Oct 2015 15:36:59 +0200 Subject: [PATCH] Don't look up joined objects when we don't need to refs #10360 --- lib/remote/objectqueryhandler.cpp | 44 +++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp index 7b1182f8a..d8565acc4 100644 --- a/lib/remote/objectqueryhandler.cpp +++ b/lib/remote/objectqueryhandler.cpp @@ -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 userJoinAttrs; + std::set 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 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 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); -- 2.50.1