Merge pull request #24295 from nextcloud/perf/noid/router

First attempt to check against core routes before loading all app routes
This commit is contained in:
blizzz 2021-06-02 21:03:29 +02:00 committed by GitHub
commit aa40bdea0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 12 deletions

View File

@ -234,32 +234,29 @@ class Router implements IRouter {
* @throws \Exception
* @return array
*/
public function findMatchingRoute(string $url): array {
if (substr($url, 0, 6) === '/apps/') {
public function findMatchingRoute(string $url, bool $loadAll = false): array {
if (strpos($url, '/apps/') === 0) {
// empty string / 'apps' / $app / rest of the route
[, , $app,] = explode('/', $url, 4);
$app = \OC_App::cleanAppId($app);
\OC::$REQUESTEDAPP = $app;
$this->loadRoutes($app);
} elseif (substr($url, 0, 13) === '/ocsapp/apps/') {
} elseif (strpos($url, '/ocsapp/apps/') === 0) {
// empty string / 'ocsapp' / 'apps' / $app / rest of the route
[, , , $app,] = explode('/', $url, 5);
$app = \OC_App::cleanAppId($app);
\OC::$REQUESTEDAPP = $app;
$this->loadRoutes($app);
} elseif (substr($url, 0, 10) === '/settings/') {
} elseif (strpos($url, '/settings/') === 0) {
$this->loadRoutes('settings');
} elseif (substr($url, 0, 6) === '/core/') {
\OC::$REQUESTEDAPP = $url;
if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
\OC_App::loadApps();
}
$this->loadRoutes('core');
} else {
$this->loadRoutes();
}
\OC::$REQUESTEDAPP = $url;
if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
\OC_App::loadApps();
}
$this->loadRoutes('core');
$matcher = new UrlMatcher($this->root, $this->context);
try {
@ -272,6 +269,11 @@ class Router implements IRouter {
try {
$parameters = $matcher->match($url . '/');
} catch (ResourceNotFoundException $newException) {
// Attempt to fallback to load all routes if none of the above route patterns matches and the route is not in core
if (!$loadAll) {
$this->loadRoutes();
return $this->findMatchingRoute($url, true);
}
// If we still didn't match a route, we throw the original exception
throw $e;
}