Skip to content

Commit

Permalink
Use caching to speed up route parsing
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Mar 14, 2020
1 parent b174f4a commit 08cea43
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.php
Expand Up @@ -7,15 +7,15 @@
use FastRoute\Dispatcher;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use function FastRoute\simpleDispatcher;
use function FastRoute\cachedDispatcher;

if (! defined('ROOT_PATH')) {
// phpcs:disable PSR1.Files.SideEffects
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
// phpcs:enable
}

global $containerBuilder, $route;
global $containerBuilder, $route, $cfg;

/** @var string $route */
$route = $_GET['route'] ?? $_POST['route'] ?? '/';
Expand All @@ -41,7 +41,12 @@
require_once ROOT_PATH . 'libraries/common.inc.php';

$routes = require ROOT_PATH . 'libraries/routes.php';
$dispatcher = simpleDispatcher($routes);
/** @var \PhpMyAdmin\Config|null $config */
$config = $GLOBALS['PMA_Config'];
$dispatcher = cachedDispatcher($routes, [
'cacheFile' => $config !== null ? $config->getTempDir('routing') . '/routes.cache' : null,
'cacheDisabled' => ($cfg['environment'] ?? '') === 'development',
]);
$routeInfo = $dispatcher->dispatch(
$_SERVER['REQUEST_METHOD'],
rawurldecode($route)
Expand Down

0 comments on commit 08cea43

Please sign in to comment.