Skip to content

Commit

Permalink
bugfix: access check was never cached
Browse files Browse the repository at this point in the history
Now the API ping result is cached for 10 minutes and can be refreshed
using the purge parameter as intended.
  • Loading branch information
splitbrain committed May 19, 2019
1 parent a8d2f3c commit 98d21c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/extension/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function handle() {
/* @var helper_plugin_extension_repository $repository */
$repository = $this->loadHelper('extension_repository');

if(!$repository->hasAccess()) {
if(!$repository->hasAccess(!$INPUT->bool('purge'))) {
$url = $this->gui->tabURL('', array('purge' => 1));
msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1);
}
Expand Down Expand Up @@ -156,4 +156,4 @@ public function html() {
}
}

// vim:ts=4:sw=4:et:
// vim:ts=4:sw=4:et:
5 changes: 3 additions & 2 deletions lib/plugins/extension/helper/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ public function init() {
/**
* If repository access is available
*
* @param bool $usecache use cached result if still valid
* @return bool If repository access is available
*/
public function hasAccess() {
public function hasAccess($usecache = true) {
if ($this->has_access === null) {
$cache = new cache('##extension_manager###hasAccess', '.repo');

if (!$cache->useCache(array('age' => 3600 * 24, 'purge'=>1))) {
if (!$cache->useCache(array('age' => 60*10, 'purge' => !$usecache))) {
$httpclient = new DokuHTTPClient();
$httpclient->timeout = 5;
$data = $httpclient->get(EXTENSION_REPOSITORY_API.'?cmd=ping');
Expand Down

0 comments on commit 98d21c0

Please sign in to comment.