Skip to content
Snippets Groups Projects
Commit f1c917eb authored by Julian's avatar Julian
Browse files

In-request caching of getUserData requests

parent 697165fe
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,8 @@ class auth_plugin_authuffd extends DokuWiki_Auth_Plugin ...@@ -10,6 +10,8 @@ class auth_plugin_authuffd extends DokuWiki_Auth_Plugin
{ {
parent::__construct(); parent::__construct();
$this->cando['external'] = true; $this->cando['external'] = true;
$this->api_client = null;
$this->api_user_cache = array();
} }
private function getOAuth2RedirectURI() private function getOAuth2RedirectURI()
...@@ -136,23 +138,32 @@ class auth_plugin_authuffd extends DokuWiki_Auth_Plugin ...@@ -136,23 +138,32 @@ class auth_plugin_authuffd extends DokuWiki_Auth_Plugin
{ {
if ($_SESSION[DOKU_COOKIE]['auth']['user'] == $user) if ($_SESSION[DOKU_COOKIE]['auth']['user'] == $user)
return $_SESSION[DOKU_COOKIE]['auth']['info']; return $_SESSION[DOKU_COOKIE]['auth']['info'];
$http = new DokuHTTPClient; if (!$this->api_client)
$http->keep_alive = false; {
$http->user = $this->getConf('api_username'); $this->api_client = new DokuHTTPClient;
$http->pass = $this->getConf('api_password'); $this->api_client->user = $this->getConf('api_username');
$this->api_client->pass = $this->getConf('api_password');
}
if (isset($this->api_user_cache[$user]))
return $this->api_user_cache[$user];
$params = array( $params = array(
'loginname' => $user 'loginname' => $user
); );
$ok = $http->get($this->getConf('baseurl') . '/api/v1/getusers?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986)); $ok = $this->api_client->get($this->getConf('baseurl') . '/api/v1/getusers?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986));
if (!$ok || $http->status != 200) if (!$ok || $this->api_client->status != 200)
return false; return false;
$results = json_decode($http->resp_body); $results = json_decode($this->api_client->resp_body);
if (!$results) $result = false;
return false; if ($results)
return array( {
$result = array(
'name' => $results[0]->displayname, 'name' => $results[0]->displayname,
'mail' => $results[0]->email, 'mail' => $results[0]->email,
'grps' => $results[0]->groups, 'grps' => $results[0]->groups,
); );
}
$this->api_user_cache[$user] = $result;
return $result;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment