Skip to content

Commit d9012b5

Browse files
committed
feat(dev): Add documentation for new AddMissingIndicesEvent
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 8f349e7 commit d9012b5

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_28.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ If you want to support Nextcloud 27 and Nextcloud 28:
9898
$eventSource = \OCP\Server::get(IEventSourceFactory::class)->create();
9999
}
100100
101+
Added events
102+
^^^^^^^^^^^^
103+
104+
* ``\OCP\DB\Events\AddMissingIndicesEvent`` to add missing indices to the database schema.
105+
101106
Deprecated events
102107
^^^^^^^^^^^^^^^^^
103108

developer_manual/basics/events.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,17 @@ It is an event that allows apps to notify other components about an interaction
453453

454454
Emitters should add at least one identifier (uid, email, federated cloud ID) of the recipient of the interaction.
455455

456+
``\OCP\DB\Events\AddMissingIndicesEvent``
457+
************************************************
458+
459+
.. versionadded:: 28
460+
461+
Event to allow apps to register information about missing database indices
462+
463+
This event will be dispatched for checking on the admin settings and when running
464+
``occ db:add-missing-indices`` which will then create those indices or can be used
465+
to generate the SQL statements for manual execution.
466+
456467
``\OCP\DirectEditing\RegisterDirectEditorEvent``
457468
************************************************
458469

developer_manual/basics/storage/migrations.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,20 @@ Nextcloud **in debug mode**:
141141

142142
.. note:: After generating a migration, you might need to run `composer dump-autoload`
143143
to be able to execute it.
144+
145+
Adding indices
146+
--------------
147+
148+
Adding indices to existing tables can take long time, especially on large tables. Therefore it is recommended to not add the indices in the migration itself, but to indicate the index requirement to the server by adding a listener for the ``AddMissingIndicesEvent``. This way the migration can be executed in a separate step and do not block the upgrade process. For new installations the index should still be added to the migration that creates the table.
149+
150+
.. code-block:: php
151+
152+
class AddMissingIndicesListener implements IEventListener {
153+
public function handle(Event $event): void {
154+
if (!$event instanceof AddMissingIndicesEvent) {
155+
return;
156+
}
157+
158+
$event->addMissingIndex('my_table', 'my_index', ['column_a', 'column_b']);
159+
}
160+
}

0 commit comments

Comments
 (0)