Permalink
Browse files

Limit ResultSet in lucene to make it faster.

Refactor exposed parameters searches in a common method.
  • Loading branch information...
1 parent 58bbd23 commit ae95130f015541c145753452c211a3f004bfc70f @cdujeu cdujeu committed Jun 20, 2016
@@ -30,11 +30,16 @@
use Pydio\Core\Model\FilteredRepositoriesList;
use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Model\UserInterface;
+use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Utils\CookiesHelper;
use Pydio\Log\Core\AJXP_Logger;
defined('AJXP_EXEC') or die('Access not allowed');
+/**
+ * Class UsersService
+ * @package Pydio\Core\Services
+ */
class UsersService
{
/**
@@ -637,6 +642,30 @@ public static function driverSupportsAuthSchemes()
}
/**
+ * Get parameters with scope='user' expose='true' attributes.
+ * Cached in plugin service.
+ *
+ * @return array Array of [PLUGIN_ID=>id, NAME=>name] objects.
+ */
+ public static function getUsersExposedParameters(){
+ $exposed = PluginsService::searchManifestsWithCache("//server_settings/param[contains(@scope,'user') and @expose='true']", function($nodes){
+ $result = [];
+ /** @var \DOMElement $exposed_prop */
+ foreach($nodes as $exposed_prop){
+ $parentNode = $exposed_prop->parentNode->parentNode;
+ $pluginId = $parentNode->getAttribute("id");
+ if (empty($pluginId)) {
+ $pluginId = $parentNode->nodeName.".".$parentNode->getAttribute("name");
+ }
+ $paramName = $exposed_prop->getAttribute("name");
+ $result[] = ["PLUGIN_ID" => $pluginId, "NAME" => $paramName];
+ }
+ return $result;
+ });
+ return $exposed;
+ }
+
+ /**
* @param string $parameterName Plugin parameter name
* @param UserInterface|string $userIdOrObject
* @param string $pluginId Plugin name, core.conf by default
@@ -134,13 +134,8 @@ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$
}
}
- $hasExposed = PluginsService::searchManifestsWithCache("//server_settings/param[contains(@scope,'user') and @expose='true']", function ($nodes) {
- return (is_array($nodes) && count($nodes));
- }, function($test){
- return ($test !== null);
- });
-
- if (!$hasExposed) {
+ $exposed = UsersService::getUsersExposedParameters();
+ if (!count($exposed)) {
$actionXpath=new \DOMXPath($contribNode->ownerDocument);
$publicUrlNodeList = $actionXpath->query('action[@name="custom_data_edit"]', $contribNode);
$publicUrlNode = $publicUrlNodeList->item(0);
@@ -555,22 +550,9 @@ public function getExposedPreferences($userObject)
$prefs[$pref] = ["value" => $userObject->getPref($pref), "type" => "json"];
}
- $exposed = PluginsService::searchManifestsWithCache("//server_settings/param[contains(@scope,'user') and @expose='true']", function($nodes){
- $result = [];
- foreach($nodes as $exposed_prop){
- $parentNode = $exposed_prop->parentNode->parentNode;
- $pluginId = $parentNode->getAttribute("id");
- if (empty($pluginId)) {
- $pluginId = $parentNode->nodeName.".".$parentNode->getAttribute("name");
- }
- $paramName = $exposed_prop->getAttribute("name");
- $result[] = ["PLUGIN_ID" => $pluginId, "NAME" => $paramName];
- }
- return $result;
- });
-
+ $exposed = UsersService::getUsersExposedParameters();
foreach ($exposed as $exposedProp) {
- $value = $userObject->mergedRole->filterParameterValue($exposedProp["PLUGIN_ID"], $exposedProp["NAME"], AJXP_REPO_SCOPE_ALL, "");
+ $value = $userObject->getMergedRole()->filterParameterValue($exposedProp["PLUGIN_ID"], $exposedProp["NAME"], AJXP_REPO_SCOPE_ALL, "");
$prefs[$exposedProp["NAME"]] = ["value" => $value, "type" => "string", "pluginId" => $exposedProp["PLUGIN_ID"]];
}
@@ -799,30 +781,22 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
Utils::parseStandardFormParameters($ctx, $httpVars, $data, "PREFERENCES_");
}
- $paramNodes = PluginsService::getInstance($ctx)->searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true);
$rChanges = false;
- if (is_array($paramNodes) && count($paramNodes)) {
- foreach ($paramNodes as $xmlNode) {
- if ($xmlNode->getAttribute("expose") == "true") {
- $parentNode = $xmlNode->parentNode->parentNode;
- $pluginId = $parentNode->getAttribute("id");
- if (empty($pluginId)) {
- $pluginId = $parentNode->nodeName.".".$parentNode->getAttribute("name");
- }
- $name = $xmlNode->getAttribute("name");
- if (isSet($data[$name]) || $data[$name] === "") {
- if($data[$name] == "__AJXP_VALUE_SET__") continue;
- $pRole = null;
- $persRole = $userObject->getPersonalRole();
- if($userObject instanceof AbstractAjxpUser) $pRole = $userObject->parentRole;
- if ($data[$name] === ""
- || $pRole === null || $pRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name]
- || $persRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name])
- {
- $persRole->setParameterValue($pluginId, $name, $data[$name]);
- $rChanges = true;
- }
- }
+ $exposed = UsersService::getUsersExposedParameters();
+ foreach($exposed as $parameter){
+ $pluginId = $parameter["PLUGIN_ID"];
+ $name = $parameter["NAME"];
+ if (isSet($data[$name]) || $data[$name] === "") {
+ if($data[$name] == "__AJXP_VALUE_SET__") continue;
+ $pRole = null;
+ $persRole = $userObject->getPersonalRole();
+ if($userObject instanceof AbstractAjxpUser) $pRole = $userObject->parentRole;
+ if ($data[$name] === ""
+ || $pRole === null || $pRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name]
+ || $persRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name])
+ {
+ $persRole->setParameterValue($pluginId, $name, $data[$name]);
+ $rChanges = true;
}
}
}
@@ -212,9 +212,13 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface &$requestIn
if ($query == "*") {
$index->setDefaultSearchField("ajxp_node");
$query = "yes";
- $hits = $index->find($query, "node_url", SORT_STRING);
+ $hits = $index->find($query);
} else {
- //$index->setResultSetLimit( isSet($httpVars["limit"]) ? intval($httpVars["limit"]) + 1 : 100 );
+ if(isSet($httpVars["limit"])){
+ $limit = intval($httpVars["limit"]);
+ // Ask one more to detect if there is "more" results or not.
+ $index->setResultSetLimit( $limit + 50 );
+ }
$hits = $index->find($query);
}
$commitIndex = false;
@@ -223,9 +227,6 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface &$requestIn
$x->addChunk($nodesList);
$cursor = 0;
- if(isSet($httpVars['limit'])){
- $limit = intval($httpVars['limit']);
- }
if(!empty($limit) && count($hits) > $limit){
$nodesList->setPaginationData(count($hits), 1, 1);
}
@@ -310,7 +311,7 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface &$requestIn
}
$query = implode(" AND ", $sParts);
$this->logDebug("Query : $query");
-// $index->setResultSetLimit(40);
+ $index->setResultSetLimit(isSet($httpVars["limit"]) ? intval($httpVars["limit"]) : 50);
$hits = $index->find($query);
$commitIndex = false;

0 comments on commit ae95130

Please sign in to comment.