cache result of \OCP\Util::needUpgrade()

reduce calls of \OCP\Util::needUpgrade()
where \OCP\Util::needUpgrade() is called we can call as well
self::checkUpgrade and use the cached result
In line 877 the call way unnecessary anyway because of the first part of
the if statement

move caching to \OCP\Util::needUpgrade

renaming variable

fixing testNeedUpgradeCore()

cache result of checkUpgrade() in self::$needUpgrade

reduce calls of \OCP\Util::needUpgrade()
where \OCP\Util::needUpgrade() is called we can call as well
self::checkUpgrade and use the cached result
In line 877 the call way unnecessary anyway because of the first part of
the if statement

move caching to \OCP\Util::needUpgrade

renaming variable

fixing testNeedUpgradeCore()

fix typo in variable name

deleting tabs
This commit is contained in:
Individual IT Services 2015-09-10 10:05:07 +05:45 committed by Thomas Müller
parent 1abd4f52bb
commit fbe43e6a26
3 changed files with 12 additions and 7 deletions

View File

@ -237,7 +237,7 @@ class OC {
// Check if config is writable // Check if config is writable
$configFileWritable = is_writable($configFilePath); $configFileWritable = is_writable($configFilePath);
if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled()
|| !$configFileWritable && \OCP\Util::needUpgrade()) { || !$configFileWritable && self::checkUpgrade(false)) {
if (self::$CLI) { if (self::$CLI) {
echo $l->t('Cannot write into "config" directory!')."\n"; echo $l->t('Cannot write into "config" directory!')."\n";
echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n";
@ -678,7 +678,7 @@ class OC {
*/ */
public static function registerCacheHooks() { public static function registerCacheHooks() {
//don't try to do this before we are properly setup //don't try to do this before we are properly setup
if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) {
// NOTE: This will be replaced to use OCP // NOTE: This will be replaced to use OCP
$userSession = self::$server->getUserSession(); $userSession = self::$server->getUserSession();
@ -714,7 +714,7 @@ class OC {
*/ */
public static function registerLogRotate() { public static function registerLogRotate() {
$systemConfig = \OC::$server->getSystemConfig(); $systemConfig = \OC::$server->getSystemConfig();
if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !\OCP\Util::needUpgrade()) { if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !self::checkUpgrade(false)) {
//don't try to do this before we are properly setup //don't try to do this before we are properly setup
//use custom logfile path if defined, otherwise use default of owncloud.log in data directory //use custom logfile path if defined, otherwise use default of owncloud.log in data directory
\OCP\BackgroundJob::registerJob('OC\Log\Rotate', $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/owncloud.log')); \OCP\BackgroundJob::registerJob('OC\Log\Rotate', $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/owncloud.log'));
@ -807,8 +807,7 @@ class OC {
// Load minimum set of apps // Load minimum set of apps
if (!self::checkUpgrade(false) if (!self::checkUpgrade(false)
&& !$systemConfig->getValue('maintenance', false) && !$systemConfig->getValue('maintenance', false)) {
&& !\OCP\Util::needUpgrade()) {
// For logged-in users: Load everything // For logged-in users: Load everything
if(OC_User::isLoggedIn()) { if(OC_User::isLoggedIn()) {
OC_App::loadApps(); OC_App::loadApps();
@ -821,7 +820,7 @@ class OC {
if (!self::$CLI and (!isset($_GET["logout"]) or ($_GET["logout"] !== 'true'))) { if (!self::$CLI and (!isset($_GET["logout"]) or ($_GET["logout"] !== 'true'))) {
try { try {
if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) {
OC_App::loadApps(array('filesystem', 'logging')); OC_App::loadApps(array('filesystem', 'logging'));
OC_App::loadApps(); OC_App::loadApps();
} }

View File

@ -654,6 +654,7 @@ class Util {
return \OC_Util::isDefaultExpireDateEnforced(); return \OC_Util::isDefaultExpireDateEnforced();
} }
protected static $needUpgradeCache = null;
/** /**
* Checks whether the current version needs upgrade. * Checks whether the current version needs upgrade.
@ -662,6 +663,9 @@ class Util {
* @since 7.0.0 * @since 7.0.0
*/ */
public static function needUpgrade() { public static function needUpgrade() {
return \OC_Util::needUpgrade(\OC::$server->getConfig()); if (!isset(self::$needUpgradeCache)) {
self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getConfig());
}
return self::$needUpgradeCache;
} }
} }

View File

@ -406,11 +406,13 @@ class Test_Util extends \Test\TestCase {
OC_Config::setValue('version', '7.0.0.0'); OC_Config::setValue('version', '7.0.0.0');
\OC::$server->getSession()->set('OC_Version', array(7, 0, 0, 1)); \OC::$server->getSession()->set('OC_Version', array(7, 0, 0, 1));
self::invokePrivate(new \OCP\Util, 'needUpgradeCache', array(null));
$this->assertTrue(\OCP\Util::needUpgrade()); $this->assertTrue(\OCP\Util::needUpgrade());
OC_Config::setValue('version', $oldConfigVersion); OC_Config::setValue('version', $oldConfigVersion);
$oldSessionVersion = \OC::$server->getSession()->set('OC_Version', $oldSessionVersion); $oldSessionVersion = \OC::$server->getSession()->set('OC_Version', $oldSessionVersion);
self::invokePrivate(new \OCP\Util, 'needUpgradeCache', array(null));
$this->assertFalse(\OCP\Util::needUpgrade()); $this->assertFalse(\OCP\Util::needUpgrade());
} }