Skip to content

Commit

Permalink
Merge pull request #9254 from nextcloud/fix/index-with-length
Browse files Browse the repository at this point in the history
fix(db): add version check for index with length
  • Loading branch information
ChristophWurst authored Jan 17, 2024
2 parents e846622 + 2cafaa1 commit 2147b54
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/Listener/OptionalIndicesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,35 @@
use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;

/**
* @template-implements IEventListener<Event|OptionalIndicesListener>
*/
class OptionalIndicesListener implements IEventListener {

/** @var IConfig */
private $config;

public function __construct(IConfig $config) {
$this->config = $config;
}

public function handle(Event $event): void {
if (!($event instanceof AddMissingIndicesEvent)) {
return;
}

$event->addMissingIndex(
'mail_messages',
'mail_messages_msgid_idx',
['message_id'],
[
'lengths' => [128],
],
);
if (version_compare($this->config->getSystemValue('version', '0.0.0'), '28.0.0', '>=')) {
$event->addMissingIndex(
'mail_messages',
'mail_messages_msgid_idx',
['message_id'],
[
'lengths' => [128],
],
);
}
}

}

0 comments on commit 2147b54

Please sign in to comment.