mirror of
https://github.com/nextcloud/server.git
synced 2025-12-18 15:56:14 -05:00
feat: Improve init a bit, and add more profiling steps
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
56897b6f3c
commit
20c6d1a7e9
8 changed files with 52 additions and 36 deletions
|
|
@ -52,6 +52,7 @@ class NextcloudNamespaceSkipVoter implements ClassNameImportSkipVoterInterface {
|
|||
$config = RectorConfig::configure()
|
||||
->withPaths([
|
||||
$nextcloudDir . '/apps',
|
||||
$nextcloudDir . '/status.php',
|
||||
// $nextcloudDir . '/config',
|
||||
// $nextcloudDir . '/core',
|
||||
// $nextcloudDir . '/lib',
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ class Autoloader {
|
|||
|
||||
/**
|
||||
* Optional low-latency memory cache for class to path mapping.
|
||||
*
|
||||
* @var \OC\Memcache\Cache
|
||||
*/
|
||||
protected $memoryCache;
|
||||
protected ?ICache $memoryCache = null;
|
||||
|
||||
/**
|
||||
* Autoloader constructor.
|
||||
|
|
@ -127,15 +125,15 @@ class Autoloader {
|
|||
* @throws AutoloadNotAllowedException
|
||||
*/
|
||||
public function load(string $class): bool {
|
||||
if (class_exists($class, false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pathsToRequire = null;
|
||||
if ($this->memoryCache) {
|
||||
$pathsToRequire = $this->memoryCache->get($class);
|
||||
}
|
||||
|
||||
if (class_exists($class, false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($pathsToRequire)) {
|
||||
// No cache or cache miss
|
||||
$pathsToRequire = [];
|
||||
|
|
|
|||
|
|
@ -188,8 +188,6 @@ class OC {
|
|||
}
|
||||
|
||||
public static function checkConfig(): void {
|
||||
$l = Server::get(\OCP\L10N\IFactory::class)->get('lib');
|
||||
|
||||
// Create config if it does not already exist
|
||||
$configFilePath = self::$configDir . '/config.php';
|
||||
if (!file_exists($configFilePath)) {
|
||||
|
|
@ -201,6 +199,7 @@ class OC {
|
|||
if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled()
|
||||
|| !$configFileWritable && \OCP\Util::needUpgrade()) {
|
||||
$urlGenerator = Server::get(IURLGenerator::class);
|
||||
$l = Server::get(\OCP\L10N\IFactory::class)->get('lib');
|
||||
|
||||
if (self::$CLI) {
|
||||
echo $l->t('Cannot write into "config" directory!') . "\n";
|
||||
|
|
@ -711,6 +710,7 @@ class OC {
|
|||
self::performSameSiteCookieProtection($config);
|
||||
|
||||
if (!defined('OC_CONSOLE')) {
|
||||
$eventLogger->start('check_server', 'Run a few configuration checks');
|
||||
$errors = OC_Util::checkServer($systemConfig);
|
||||
if (count($errors) > 0) {
|
||||
if (!self::$CLI) {
|
||||
|
|
@ -745,6 +745,7 @@ class OC {
|
|||
} elseif (self::$CLI && $config->getSystemValueBool('installed', false)) {
|
||||
$config->deleteAppValue('core', 'cronErrors');
|
||||
}
|
||||
$eventLogger->end('check_server');
|
||||
}
|
||||
|
||||
// User and Groups
|
||||
|
|
@ -752,6 +753,7 @@ class OC {
|
|||
self::$server->getSession()->set('user_id', '');
|
||||
}
|
||||
|
||||
$eventLogger->start('setup_backends', 'Setup group and user backends');
|
||||
Server::get(\OCP\IUserManager::class)->registerBackend(new \OC\User\Database());
|
||||
Server::get(\OCP\IGroupManager::class)->addBackend(new \OC\Group\Database());
|
||||
|
||||
|
|
@ -770,6 +772,7 @@ class OC {
|
|||
// Run upgrades in incognito mode
|
||||
OC_User::setIncognitoMode(true);
|
||||
}
|
||||
$eventLogger->end('setup_backends');
|
||||
|
||||
self::registerCleanupHooks($systemConfig);
|
||||
self::registerShareHooks($systemConfig);
|
||||
|
|
|
|||
|
|
@ -83,10 +83,10 @@ class Coordinator {
|
|||
$appNameSpace = App::buildAppNamespace($appId);
|
||||
$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
|
||||
try {
|
||||
if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) {
|
||||
if (class_exists($applicationClassName) && is_a($applicationClassName, IBootstrap::class, true)) {
|
||||
$this->eventLogger->start("bootstrap:register_app:$appId:application", "Load `Application` instance for $appId");
|
||||
try {
|
||||
/** @var IBootstrap|App $application */
|
||||
/** @var IBootstrap&App $application */
|
||||
$apps[$appId] = $application = $this->serverContainer->query($applicationClassName);
|
||||
} catch (QueryException $e) {
|
||||
// Weird, but ok
|
||||
|
|
|
|||
|
|
@ -153,13 +153,13 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer {
|
|||
return $closure($this);
|
||||
};
|
||||
$name = $this->sanitizeName($name);
|
||||
if (isset($this[$name])) {
|
||||
unset($this[$name]);
|
||||
if (isset($this->container[$name])) {
|
||||
unset($this->container[$name]);
|
||||
}
|
||||
if ($shared) {
|
||||
$this[$name] = $wrapped;
|
||||
$this->container[$name] = $wrapped;
|
||||
} else {
|
||||
$this[$name] = $this->container->factory($wrapped);
|
||||
$this->container[$name] = $this->container->factory($wrapped);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ class Router implements IRouter {
|
|||
protected LoggerInterface $logger,
|
||||
IRequest $request,
|
||||
private IConfig $config,
|
||||
private IEventLogger $eventLogger,
|
||||
protected IEventLogger $eventLogger,
|
||||
private ContainerInterface $container,
|
||||
private IAppManager $appManager,
|
||||
protected IAppManager $appManager,
|
||||
) {
|
||||
$baseUrl = \OC::$WEBROOT;
|
||||
if (!($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
|
||||
|
|
@ -116,9 +116,11 @@ class Router implements IRouter {
|
|||
$this->loaded = true;
|
||||
$routingFiles = $this->getRoutingFiles();
|
||||
|
||||
$this->eventLogger->start('route:load:attributes', 'Loading Routes from attributes');
|
||||
foreach (\OC_App::getEnabledApps() as $enabledApp) {
|
||||
$this->loadAttributeRoutes($enabledApp);
|
||||
}
|
||||
$this->eventLogger->end('route:load:attributes');
|
||||
} else {
|
||||
if (isset($this->loadedApps[$app])) {
|
||||
return;
|
||||
|
|
@ -140,6 +142,7 @@ class Router implements IRouter {
|
|||
}
|
||||
}
|
||||
|
||||
$this->eventLogger->start('route:load:files', 'Loading Routes from files');
|
||||
foreach ($routingFiles as $app => $file) {
|
||||
if (!isset($this->loadedApps[$app])) {
|
||||
if (!$this->appManager->isAppLoaded($app)) {
|
||||
|
|
@ -160,6 +163,7 @@ class Router implements IRouter {
|
|||
$this->root->addCollection($collection);
|
||||
}
|
||||
}
|
||||
$this->eventLogger->end('route:load:files');
|
||||
|
||||
if (!isset($this->loadedApps['core'])) {
|
||||
$this->loadedApps['core'] = true;
|
||||
|
|
@ -265,6 +269,7 @@ class Router implements IRouter {
|
|||
$this->loadRoutes();
|
||||
}
|
||||
|
||||
$this->eventLogger->start('route:url:match', 'Symfony url matcher call');
|
||||
$matcher = new UrlMatcher($this->root, $this->context);
|
||||
try {
|
||||
$parameters = $matcher->match($url);
|
||||
|
|
@ -283,6 +288,7 @@ class Router implements IRouter {
|
|||
throw $e;
|
||||
}
|
||||
}
|
||||
$this->eventLogger->end('route:url:match');
|
||||
|
||||
$this->eventLogger->end('route:match');
|
||||
return $parameters;
|
||||
|
|
|
|||
|
|
@ -128,18 +128,17 @@ class ServerContainer extends SimpleContainer {
|
|||
} catch (QueryException $e) {
|
||||
// Continue with general autoloading then
|
||||
}
|
||||
}
|
||||
|
||||
// In case the service starts with OCA\ we try to find the service in
|
||||
// the apps container first.
|
||||
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
|
||||
try {
|
||||
return $appContainer->queryNoFallback($name);
|
||||
} catch (QueryException $e) {
|
||||
// Didn't find the service or the respective app container
|
||||
// In this case the service won't be part of the core container,
|
||||
// so we can throw directly
|
||||
throw $e;
|
||||
// In case the service starts with OCA\ we try to find the service in
|
||||
// the apps container first.
|
||||
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
|
||||
try {
|
||||
return $appContainer->queryNoFallback($name);
|
||||
} catch (QueryException $e) {
|
||||
// Didn't find the service or the respective app container
|
||||
// In this case the service won't be part of the core container,
|
||||
// so we can throw directly
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
} elseif (str_starts_with($name, 'OC\\Settings\\') && substr_count($name, '\\') >= 3) {
|
||||
$segments = explode('\\', $name);
|
||||
|
|
|
|||
23
status.php
23
status.php
|
|
@ -1,33 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/lib/versioncheck.php';
|
||||
|
||||
use OC\SystemConfig;
|
||||
use OCP\Defaults;
|
||||
use OCP\Server;
|
||||
use OCP\ServerVersion;
|
||||
use OCP\Util;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
try {
|
||||
require_once __DIR__ . '/lib/base.php';
|
||||
|
||||
$systemConfig = \OC::$server->getSystemConfig();
|
||||
$systemConfig = Server::get(SystemConfig::class);
|
||||
|
||||
$installed = (bool)$systemConfig->getValue('installed', false);
|
||||
$maintenance = (bool)$systemConfig->getValue('maintenance', false);
|
||||
# see core/lib/private/legacy/defaults.php and core/themes/example/defaults.php
|
||||
# for description and defaults
|
||||
$defaults = new \OCP\Defaults();
|
||||
$defaults = new Defaults();
|
||||
$serverVersion = Server::get(ServerVersion::class);
|
||||
$values = [
|
||||
'installed' => $installed,
|
||||
'maintenance' => $maintenance,
|
||||
'needsDbUpgrade' => \OCP\Util::needUpgrade(),
|
||||
'version' => implode('.', \OCP\Util::getVersion()),
|
||||
'versionstring' => \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString(),
|
||||
'needsDbUpgrade' => Util::needUpgrade(),
|
||||
'version' => implode('.', $serverVersion->getVersion()),
|
||||
'versionstring' => $serverVersion->getVersionString(),
|
||||
'edition' => '',
|
||||
'productname' => $defaults->getProductName(),
|
||||
'extendedSupport' => \OCP\Util::hasExtendedSupport()
|
||||
'extendedSupport' => Util::hasExtendedSupport()
|
||||
];
|
||||
if (OC::$CLI) {
|
||||
print_r($values);
|
||||
|
|
@ -38,5 +47,5 @@ try {
|
|||
}
|
||||
} catch (Exception $ex) {
|
||||
http_response_code(500);
|
||||
\OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'remote','exception' => $ex]);
|
||||
Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'remote','exception' => $ex]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue