diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index e18dcc5ff8ef0..e030165bb6e86 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -19,6 +19,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IRequest; +use OCP\ITempManager; use OCP\Server; use OCP\ServerVersion; use OCP\Util; @@ -42,6 +43,7 @@ public function __construct( private MemoryInfo $memoryInfo, private IAppManager $appManager, private Defaults $defaults, + private ITempManager $tempManager, ) { $this->application = new SymfonyApplication($defaults->getName(), $serverVersion->getVersionString()); } @@ -81,6 +83,16 @@ public function loadCommands( ); } + $cacheFilePath = $this->tempManager->getTempBaseDir() . '/nextcloud_commands.json'; + if (file_exists($cacheFilePath)) { + $commandsCache = json_decode(file_get_contents($cacheFilePath), associative:true); + $firstArg = $input->getFirstArgument(); + if (isset($commandsCache[$firstArg])) { + $this->application->add(Server::get($commandsCache[$firstArg])); + return; + } + } + try { require_once __DIR__ . '/../../../core/register_command.php'; if ($this->config->getSystemValueBool('installed', false)) { @@ -161,6 +173,19 @@ public function loadCommands( throw new \Exception('Environment not properly prepared.'); } } + $commands = $this->application->all(); + $cache = []; + foreach ($commands as $command) { + $name = $command->getName(); + if ($name !== null) { + $cache[$name] = $command::class; + } + + foreach ($command->getAliases() as $alias) { + $cache[$alias] = $command::class; + } + } + file_put_contents($cacheFilePath, json_encode($cache)); } /**