Skip to content

Commit fb6aeaa

Browse files
committed
fixup! Add missing index
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 36e0c3e commit fb6aeaa

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class CheckSetupController extends Controller {
110110
private $iniGetWrapper;
111111
/** @var IDBConnection */
112112
private $connection;
113+
/** @var OC\AppFramework\Maintenance\OptionalIndexManager */
114+
private $indexManager;
113115

114116
public function __construct($AppName,
115117
IRequest $request,
@@ -126,7 +128,8 @@ public function __construct($AppName,
126128
MemoryInfo $memoryInfo,
127129
ISecureRandom $secureRandom,
128130
IniGetWrapper $iniGetWrapper,
129-
IDBConnection $connection) {
131+
IDBConnection $connection,
132+
OC\AppFramework\Maintenance\OptionalIndexManager $indexManager) {
130133
parent::__construct($AppName, $request);
131134
$this->config = $config;
132135
$this->clientService = $clientService;
@@ -142,6 +145,7 @@ public function __construct($AppName,
142145
$this->secureRandom = $secureRandom;
143146
$this->iniGetWrapper = $iniGetWrapper;
144147
$this->connection = $connection;
148+
$this->indexManager = $indexManager;
145149
}
146150

147151
/**
@@ -466,6 +470,11 @@ protected function hasMissingIndexes(): array {
466470
$event = new GenericEvent($indexInfo);
467471
$this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event);
468472

473+
$indexes = $this->indexManager->getPending();
474+
foreach ($indexes as $index) {
475+
$indexInfo->addHintForMissingSubject($index->getTable(), $index->getName());
476+
}
477+
469478
return $indexInfo->getListOfMissingIndexes();
470479
}
471480

core/Command/Db/AddMissingIndices.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
namespace OC\Core\Command\Db;
3535

36+
use OC\AppFramework\Maintenance\OptionalIndexManager;
3637
use OC\DB\Connection;
3738
use OC\DB\SchemaWrapper;
3839
use OCP\IDBConnection;
@@ -58,11 +59,17 @@ class AddMissingIndices extends Command {
5859
/** @var EventDispatcherInterface */
5960
private $dispatcher;
6061

61-
public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
62+
/** @var OptionalIndexManager */
63+
private $indexManager;
64+
65+
public function __construct(Connection $connection,
66+
EventDispatcherInterface $dispatcher,
67+
OptionalIndexManager $indexManager) {
6268
parent::__construct();
6369

6470
$this->connection = $connection;
6571
$this->dispatcher = $dispatcher;
72+
$this->indexManager = $indexManager;
6673
}
6774

6875
protected function configure() {
@@ -77,9 +84,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7784
// Dispatch event so apps can also update indexes if needed
7885
$event = new GenericEvent($output);
7986
$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
87+
88+
$this->addOptionalIndexed($output);
89+
8090
return 0;
8191
}
8292

93+
private function addOptionalIndexed(OutputInterface $output): void {
94+
$indexes = $this->indexManager->getPending();
95+
96+
foreach ($indexes as $index) {
97+
$output->writeln('<info>Adding additonal ' . $index->getName() . ' index to the ' . $index->getTable() . ' this can take some time..</info>');
98+
$index->add();
99+
}
100+
}
101+
83102
/**
84103
* add missing indices to the share table
85104
*

lib/public/AppFramework/Maintenance/IOptionalIndex.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ interface IOptionalIndex {
3838
*/
3939
public function getName(): string;
4040

41+
/**
42+
* Get the name of the table this operates on
43+
*
44+
* @since 22.0.0
45+
* @return string
46+
*/
47+
public function getTable(): string;
48+
4149
/**
4250
* Does the optional index already exist
4351
*

0 commit comments

Comments
 (0)