Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/private/legacy/OC_Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\ISession;
use OCP\ICacheFactory;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
Expand Down Expand Up @@ -261,6 +261,7 @@ public static function addHeader($tag, $attributes, $text = null, $prepend = fal
*/
public static function checkServer(SystemConfig $config) {
$l = \OC::$server->getL10N('lib');
$localCache = Server::get(ICacheFactory::class)->createLocal('system');
$errors = [];
$CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data');

Expand All @@ -269,8 +270,8 @@ public static function checkServer(SystemConfig $config) {
$errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
}

// Assume that if checkServer() succeeded before in this session, then all is fine.
if (Server::get(ISession::class)->exists('checkServer_succeeded') && Server::get(ISession::class)->get('checkServer_succeeded')) {
// Skip re-evaluation if everything is fine
if ($localCache->get('checkServer_succeeded') === true) {
return $errors;
}

Expand Down Expand Up @@ -439,8 +440,8 @@ public static function checkServer(SystemConfig $config) {
}
}

// Cache the result of this function
Server::get(ISession::class)->set('checkServer_succeeded', count($errors) == 0);
// Cache the result of this function for an hour
$localCache->set('checkServer_succeeded', $errors === [], 3600);

return $errors;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/UtilCheckServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Test;

use OC\SystemConfig;
use OCP\ICacheFactory;
use OCP\ISession;
use OCP\ITempManager;
use OCP\Server;
Expand Down Expand Up @@ -47,7 +48,7 @@ protected function setUp(): void {
$this->datadir = Server::get(ITempManager::class)->getTemporaryFolder();

file_put_contents($this->datadir . '/.ncdata', '# Nextcloud data directory');
Server::get(ISession::class)->set('checkServer_succeeded', false);
Server::get(ICacheFactory::class)->createLocal('system')->set('checkServer_succeeded', false, 10);
}

#[\Override]
Expand Down
Loading