From 53d4800f6eb31da70fadd35ed19a5fcbf907f277 Mon Sep 17 00:00:00 2001 From: cdujeu Date: Tue, 2 Jun 2015 16:55:45 +0200 Subject: [PATCH] Performance: user queriesCache for exposed properties list --- .../core.conf/class.AbstractConfDriver.php | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/core/src/plugins/core.conf/class.AbstractConfDriver.php b/core/src/plugins/core.conf/class.AbstractConfDriver.php index 8146491315..10462ab2ae 100644 --- a/core/src/plugins/core.conf/class.AbstractConfDriver.php +++ b/core/src/plugins/core.conf/class.AbstractConfDriver.php @@ -517,20 +517,28 @@ public function getExposedPreferences($userObject) $prefs[$pref] = array("value" => $userObject->getPref($pref), "type" => "json" ); } - $paramNodes = AJXP_PluginsService::searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true); - 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"); - $value = $userObject->mergedRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, ""); - $prefs[$name] = array("value" => $value, "type" => "string", "pluginId" => $pluginId); + + $exposed = array(); + $cacheHasExposed = AJXP_PluginsService::getInstance()->loadFromPluginQueriesCache("//server_settings/param[contains(@scope,'user') and @expose='true']"); + if ($cacheHasExposed !== null && is_array($cacheHasExposed)) { + $exposed = $cacheHasExposed; + } else { + $exposed_props = AJXP_PluginsService::searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true); + foreach($exposed_props 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"); + $exposed[] = array("PLUGIN_ID" => $pluginId, "NAME" => $paramName); } + AJXP_PluginsService::getInstance()->storeToPluginQueriesCache("//server_settings/param[contains(@scope,'user') and @expose='true']", $exposed); + } + + foreach ($exposed as $exposedProp) { + $value = $userObject->mergedRole->filterParameterValue($exposedProp["PLUGIN_ID"], $exposedProp["NAME"], AJXP_REPO_SCOPE_ALL, ""); + $prefs[$exposedProp["NAME"]] = array("value" => $value, "type" => "string", "pluginId" => $exposedProp["PLUGIN_ID"]); } return $prefs; @@ -617,7 +625,16 @@ public function switchAction($action, $httpVars, $fileVars) echo json_encode($data); }else{ header('Content-Type: application/xml; charset=UTF-8'); - print(AJXP_XMLWriter::replaceAjxpXmlKeywords($clone->saveXML())); + $string = AJXP_XMLWriter::replaceAjxpXmlKeywords($clone->saveXML()); + $etag = md5($string); + $match = isSet($_SERVER["HTTP_IF_NONE_MATCH"])?$_SERVER["HTTP_IF_NONE_MATCH"]:''; + if($match == $etag){ + header('HTTP/1.1 304 Not Modified'); + }else{ + header('Cache-Control:public, max-age=31536000'); + header('ETag: '.$etag); + print($string); + } } }