Permalink
Browse files

Enhance performance by using graphUri directly

- model instance was only used to obtain the graph URI, which leads to some
  unneccesary  SPARQL queries
  • Loading branch information...
1 parent 756bb9f commit 922bce66fccd01036dd264d95c2354b69f10591d @pfrischmuth pfrischmuth committed Dec 11, 2012
Showing with 30 additions and 10 deletions.
  1. +17 −9 library/Erfurt/Ac/Default.php
  2. +13 −1 library/Erfurt/App.php
@@ -31,6 +31,8 @@ class Erfurt_Ac_Default
* @var Erfurt_Rdf_Model
*/
private $_acModel = null;
+
+ private $_acModelUri = null;
/**
* Contains the action configuration from the configurations (both ini and ac model).
@@ -51,6 +53,8 @@ class Erfurt_Ac_Default
private $_config = null;
private $_isInit = false;
+
+ private $_store = null;
/**
* Contains the configured ac concept uris.
@@ -130,7 +134,7 @@ public function getActionConfig($actionSpec)
}'
);
- $result = $this->_sparql($this->_acModel, $query);
+ $result = $this->_sparql($this->_acModelUri, $query);
if ($result) {
foreach ($result as $row) {
$s = $row['s'];
@@ -342,6 +346,7 @@ public function isActionAllowed($action)
} else {
// create action instance
// array for new statements (an action instance pus label)
+ /*
$actionStmt = array(
$actionUri => array (
EF_RDF_TYPE => array (
@@ -355,6 +360,7 @@ public function isActionAllowed($action)
$store = Erfurt_App::getInstance()->getStore();
$store->addMultipleStatements($this->_uris['acModelUri'], $actionStmt, false);
+ */
return false;
}
@@ -474,7 +480,7 @@ public function setUserModelRight($modelUri, $type = 'view', $perm = 'grant')
// TODO set the right cache tags, such that cache is invalidated!!!
$store = Erfurt_App::getInstance()->getStore();
$store->addStatement(
- $this->_acModel->getModelUri(),
+ $this->_acModelUri,
$user->getUri(),
$prop,
array('type' => 'uri', 'value' => $modelUri),
@@ -538,7 +544,7 @@ private function _getUserModelRights($userURI)
}'
);
- if ($result = $this->_sparql($this->_acModel, $sparqlQuery)) {
+ if ($result = $this->_sparql($this->_acModelUri, $sparqlQuery)) {
$this->_filterAccess($result, $userRights);
}
@@ -554,7 +560,7 @@ private function _getUserModelRights($userURI)
}'
);
- if ($result = $this->_sparql($this->_acModel, $sparqlQuery)) {
+ if ($result = $this->_sparql($this->_acModelUri, $sparqlQuery)) {
$this->_filterAccess($result, $userRights);
}
@@ -672,11 +678,13 @@ private function _init()
$this->_auth = $app->getAuth();
// access control informations
- $this->_acModel = $app->getAcModel();
+ //$this->_acModel = $app->getAcModel();
+ $this->_store = $app->getStore();
+ $this->_acModelUri = $app->getAcModelUri();
// get custom uri configuration
$this->_uris['acBaseUri'] = $this->_config->ac->baseUri;
- $this->_uris['acModelUri'] = $this->_acModel->getModelUri();
+ $this->_uris['acModelUri'] = $this->_acModelUri;
$this->_uris['anonymousUserUri'] = $this->_config->ac->user->anonymousUser;
$this->_uris['superUserUri'] = $this->_config->ac->user->superAdmin;
$this->_uris['propAnyModel'] = $this->_config->ac->models->anyModel;
@@ -701,10 +709,10 @@ private function _init()
* @param Erfurt_Sparql_SimpleQuery The SPARQL query.
* @return array Returns an array containig the result.
*/
- private function _sparql($model, $sparqlQuery)
+ private function _sparql($modelUri, $sparqlQuery)
{
- $sparqlQuery->addFrom($model->getModelUri());
- $result = $model->getStore()->sparqlQuery($sparqlQuery, array(Erfurt_Store::USE_AC => false));
+ $sparqlQuery->addFrom($modelUri);
+ $result = $this->_store->sparqlQuery($sparqlQuery, array(Erfurt_Store::USE_AC => false));
return $result;
}
View
@@ -62,6 +62,8 @@ class Erfurt_App
*/
private $_acModel = null;
+ private $_acModelUri = null;
+
/**
* Contains a reference to Zend_Auth singleton.
*/
@@ -549,12 +551,22 @@ public function getAcModel()
{
if (null === $this->_acModel) {
$config = $this->getConfig();
- $this->_acModel = $this->getStore()->getModel($config->ac->modelUri, false);
+ $this->_acModel = $this->getStore()->getModel($this->getAcModelUri(), false);
}
return $this->_acModel;
}
+ public function getAcModelUri()
+ {
+ if (null === $this->_acModelUri) {
+ $config = $this->getConfig();
+ $this->_acModelUri = $config->ac->modelUri;
+ }
+
+ return $this->_acModelUri;
+ }
+
/**
* Convenience shortcut for Ac_Default::getActionConfig().
*

0 comments on commit 922bce6

Please sign in to comment.