Skip to content

Commit c9293c0

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

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_28.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Due to the popularity of CLI tools for development of Nextcloud apps, the likeli
5151
Added APIs
5252
^^^^^^^^^^
5353

54+
* ``\OCP\DB\Events\AddMissingIndicesEvent`` to add missing indices to the database schema.
5455
* ``\OCP\Mail\IMessage::setSubject`` to set an email subject. See :ref:`email` for an example.
5556
* ``\OCP\Mail\IMessage::setHtmlBody`` and ``\OCP\Mail\IMessage::setPlainBody`` to set an email body See :ref:`email` for an example.
5657
* ``\OCP\IEventSourceFactory`` to create a ``OCP\IEventSource`` instance.

developer_manual/basics/events.rst

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

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

449+
``\OCP\DB\Events\AddMissingIndicesEvent``
450+
************************************************
451+
452+
.. versionadded:: 28
453+
454+
Event to allow apps to register information about missing database indices
455+
456+
This event will be dispatched for checking on the admin settings and when running
457+
``occ db:add-missing-indices`` which will then create those indices or can be used
458+
to generate the SQL statements for manual execution.
459+
449460
``\OCP\DirectEditing\RegisterDirectEditorEvent``
450461
************************************************
451462

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)