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,18 +49,44 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
qd.Types.insert(type->GetName()); qd.Types.insert(type->GetName());
qd.Permission = "objects/query/" + 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; std::vector<String> joinAttrs;
joinAttrs.push_back(""); joinAttrs.push_back("");
for (int fid = 0; fid < type->GetFieldCount(); fid++) { for (int fid = 0; fid < type->GetFieldCount(); fid++) {
Field field = type->GetFieldInfo(fid); Field field = type->GetFieldInfo(fid);
if (field.Attributes & FANavigation) if (!(field.Attributes & FANavigation))
continue;
if (!userJoinAttrs.empty() && userJoinAttrs.find(field.Name) == userJoinAttrs.end())
continue;
joinAttrs.push_back(field.Name); joinAttrs.push_back(field.Name);
} }
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
params->Set("type", type->GetName()); params->Set("type", type->GetName());
if (request.RequestUrl->GetPath().size() >= 4) { if (request.RequestUrl->GetPath().size() >= 4) {
@ -73,16 +99,6 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
Array::Ptr results = new Array(); 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) { BOOST_FOREACH(const ConfigObject::Ptr& obj, objs) {
Dictionary::Ptr result1 = new Dictionary(); Dictionary::Ptr result1 = new Dictionary();
results->Add(result1); results->Add(result1);