Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Repository switch and loading optimization: avoid loading all availab…
Browse files Browse the repository at this point in the history
…le repository when we already know the repository ID. Should have a great impact on REST-based access, typically WebDAV.
  • Loading branch information
cdujeu committed Nov 27, 2013
1 parent 9828af8 commit 5fd9a35
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/src/cmd.php
Expand Up @@ -189,7 +189,7 @@
// DRIVERS BELOW NEED IDENTIFICATION CHECK
if (!AuthService::usersEnabled() || ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth") || AuthService::getLoggedUser()!=null) {
$confDriver = ConfService::getConfStorageImpl();
$Driver = ConfService::loadRepositoryDriver();
$Driver = ConfService::loadDriverForRepository(ConfService::getRepository());
}
AJXP_PluginsService::getInstance()->initActivePlugins();
require_once(AJXP_BIN_FOLDER."/class.AJXP_Controller.php");
Expand Down
22 changes: 19 additions & 3 deletions core/src/core/classes/class.ConfService.php
Expand Up @@ -262,8 +262,8 @@ public static function switchRootDir($rootDirIndex = -1, $temporary = false)
*/
public function switchRootDirInst($rootDirIndex=-1, $temporary=false)
{
$currentRepos = $this->getLoadedRepositories();
if ($rootDirIndex == -1) {
$currentRepos = $this->getLoadedRepositories();
if (isSet($_SESSION['REPO_ID']) && array_key_exists($_SESSION['REPO_ID'], $currentRepos)) {
$this->configs["REPOSITORY"] = $currentRepos[$_SESSION['REPO_ID']];
} else {
Expand All @@ -272,6 +272,11 @@ public function switchRootDirInst($rootDirIndex=-1, $temporary=false)
$_SESSION['REPO_ID'] = $keys[0];
}
} else {
/*
if (isSet($this->configs["REPOSITORY"]) && $this->configs["REPOSITORY"] == $rootDirIndex) {
return;
}
*/
if ($temporary && isSet($_SESSION['REPO_ID'])) {
$crtId = $_SESSION['REPO_ID'];
if ($crtId != $rootDirIndex && !isSet($_SESSION['SWITCH_BACK_REPO_ID'])) {
Expand All @@ -283,7 +288,11 @@ public function switchRootDirInst($rootDirIndex=-1, $temporary=false)
$_SESSION['PREVIOUS_REPO_ID'] = $crtId;
//AJXP_Logger::debug("switching back to $rootDirIndex");
}
$this->configs["REPOSITORY"] = $currentRepos[$rootDirIndex];
if (isSet($this->configs["REPOSITORIES"]) && isSet($this->configs["REPOSITORIES"][$rootDirIndex])) {
$this->configs["REPOSITORY"] = $this->configs["REPOSITORIES"][$rootDirIndex];
} else {
$this->configs["REPOSITORY"] = ConfService::getRepositoryById($rootDirIndex);
}
$_SESSION['REPO_ID'] = $rootDirIndex;
if(isSet($this->configs["ACCESS_DRIVER"])) unset($this->configs["ACCESS_DRIVER"]);
}
Expand Down Expand Up @@ -632,10 +641,15 @@ public static function getRepositoryById($repoId)
*/
public function getRepositoryByIdInst($repoId)
{
/*
$currentRepos = $this->getLoadedRepositories();
if (isSet($currentRepos[$repoId])) {
return $currentRepos[$repoId];
}
*/
if (isSet($this->configs["REPOSITORIES"]) && isSet($this->configs["REPOSITORIES"][$repoId])) {
return $this->configs["REPOSITORIES"][$repoId];
}
return $this->getConfStorageImpl()->getRepositoryById($repoId);
}

Expand All @@ -662,7 +676,9 @@ public function getRepositoryByAliasInstDefaults($repoAlias)
$conf = $this->configs["DEFAULT_REPOSITORIES"];
foreach ($conf as $repoId => $repoDef) {
if ($repoDef["AJXP_SLUG"] == $repoAlias) {
return $this->getRepositoryByIdInst($repoId);
$repo = self::createRepositoryFromArray($repoId, $repoDef);
$repo->setWriteable(false);
return $repo;
}
}
return null;
Expand Down
Expand Up @@ -79,7 +79,7 @@ public function authenticate(Sabre\DAV\Server $server, $realm)
if ($success === false) {
throw new Sabre\DAV\Exception\NotAuthenticated();
}
ConfService::loadRepositoryDriver();
ConfService::switchRootDir($this->repositoryId);
return true;
}

Expand Down
Expand Up @@ -58,12 +58,12 @@ public function __construct($path, $repository, $accessDriver = null)
public function getAccessDriver()
{
if (!isset($this->accessDriver)) {
$RID = $this->repository->getId();
ConfService::switchRootDir($RID);
//$RID = $this->repository->getId();
//ConfService::switchRootDir($RID);
ConfService::getConfStorageImpl();
$this->accessDriver = ConfService::loadRepositoryDriver();
$this->accessDriver = ConfService::loadDriverForRepository($this->repository);
if (!$this->accessDriver instanceof AjxpWrapperProvider) {
throw new Sabre\DAV\Exception\FileNotFound( $RID );
throw new Sabre\DAV\Exception\NotFound( $this->repository->getId() );
}
$this->accessDriver->detectStreamWrapper(true);
}
Expand Down

0 comments on commit 5fd9a35

Please sign in to comment.