From 297877fdad318229f05cbbdabccead5539b91edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 7 Jul 2026 11:23:25 +0200 Subject: [PATCH] feat(occ): Cache command list to speed up occ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Console/Application.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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)); } /**