Don't look up joined objects when we don't need to

refs #10360
This commit is contained in:
Gunnar Beutner 2015-10-14 15:36:59 +02:00
parent 74aa5c1d6b
commit 48d80e29a0
1 changed files with 30 additions and 14 deletions

View 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);