diff --git a/composer.lock b/composer.lock index 4a9082f210b..ca48573fd45 100644 --- a/composer.lock +++ b/composer.lock @@ -608,12 +608,12 @@ "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "e83c3af4c37a8be5d7c6a6339f4aa2c99cc74f97" + "reference": "6f0ffec5ace13e71f50d0735c0258fc37f4ca562" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/e83c3af4c37a8be5d7c6a6339f4aa2c99cc74f97", - "reference": "e83c3af4c37a8be5d7c6a6339f4aa2c99cc74f97", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/6f0ffec5ace13e71f50d0735c0258fc37f4ca562", + "reference": "6f0ffec5ace13e71f50d0735c0258fc37f4ca562", "shasum": "" }, "require": { @@ -643,7 +643,7 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/stable26" }, - "time": "2023-07-06T00:47:48+00:00" + "time": "2023-07-17T09:26:46+00:00" }, { "name": "nikic/php-parser", diff --git a/composer/composer/autoload_classmap.php b/composer/composer/autoload_classmap.php index 6db47ec2d86..81d1e9556c8 100644 --- a/composer/composer/autoload_classmap.php +++ b/composer/composer/autoload_classmap.php @@ -31,6 +31,7 @@ 'OCA\\Text\\Exception\\DocumentSaveConflictException' => $baseDir . '/../lib/Exception/DocumentSaveConflictException.php', 'OCA\\Text\\Exception\\UploadException' => $baseDir . '/../lib/Exception/UploadException.php', 'OCA\\Text\\Exception\\VersionMismatchException' => $baseDir . '/../lib/Exception/VersionMismatchException.php', + 'OCA\\Text\\Listeners\\AddMissingIndicesListener' => $baseDir . '/../lib/Listeners/AddMissingIndicesListener.php', 'OCA\\Text\\Listeners\\BeforeNodeDeletedListener' => $baseDir . '/../lib/Listeners/BeforeNodeDeletedListener.php', 'OCA\\Text\\Listeners\\BeforeNodeRenamedListener' => $baseDir . '/../lib/Listeners/BeforeNodeRenamedListener.php', 'OCA\\Text\\Listeners\\FilesLoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/FilesLoadAdditionalScriptsListener.php', diff --git a/composer/composer/autoload_static.php b/composer/composer/autoload_static.php index 5246ab8c713..49170347b5c 100644 --- a/composer/composer/autoload_static.php +++ b/composer/composer/autoload_static.php @@ -46,6 +46,7 @@ class ComposerStaticInitText 'OCA\\Text\\Exception\\DocumentSaveConflictException' => __DIR__ . '/..' . '/../lib/Exception/DocumentSaveConflictException.php', 'OCA\\Text\\Exception\\UploadException' => __DIR__ . '/..' . '/../lib/Exception/UploadException.php', 'OCA\\Text\\Exception\\VersionMismatchException' => __DIR__ . '/..' . '/../lib/Exception/VersionMismatchException.php', + 'OCA\\Text\\Listeners\\AddMissingIndicesListener' => __DIR__ . '/..' . '/../lib/Listeners/AddMissingIndicesListener.php', 'OCA\\Text\\Listeners\\BeforeNodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeNodeDeletedListener.php', 'OCA\\Text\\Listeners\\BeforeNodeRenamedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeNodeRenamedListener.php', 'OCA\\Text\\Listeners\\FilesLoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/FilesLoadAdditionalScriptsListener.php', diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 5dd83a2ba0c..8a7fb50d556 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -28,6 +28,7 @@ use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\Text\Event\LoadEditor; +use OCA\Text\Listeners\AddMissingIndicesListener; use OCA\Text\Listeners\BeforeNodeDeletedListener; use OCA\Text\Listeners\BeforeNodeRenamedListener; use OCA\Text\Listeners\LoadEditorListener; @@ -43,6 +44,7 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\DB\Events\AddMissingIndicesEvent; use OCP\DirectEditing\RegisterDirectEditorEvent; use OCP\Files\Events\Node\BeforeNodeDeletedEvent; use OCP\Files\Events\Node\BeforeNodeRenamedEvent; @@ -68,6 +70,7 @@ public function register(IRegistrationContext $context): void { $context->registerEventListener(NodeCopiedEvent::class, NodeCopiedListener::class); $context->registerEventListener(BeforeNodeRenamedEvent::class, BeforeNodeRenamedListener::class); $context->registerEventListener(BeforeNodeDeletedEvent::class, BeforeNodeDeletedListener::class); + $context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class); $context->registerNotifierService(Notifier::class); } diff --git a/lib/Db/SessionMapper.php b/lib/Db/SessionMapper.php index c6eb7045dd3..19893b697ea 100644 --- a/lib/Db/SessionMapper.php +++ b/lib/Db/SessionMapper.php @@ -111,8 +111,13 @@ public function deleteInactiveWithoutSteps(?int $documentId = null): int { } $qb = $this->db->getQueryBuilder(); - $qb->delete($this->getTableName()) - ->where($qb->expr()->in('id', $qb->createFunction($selectSubQuery->getSQL()))); + $qb->delete($this->getTableName()); + if ($documentId !== null) { + $qb->where($selectSubQuery->expr()->eq('document_id', $selectSubQuery->createParameter('documentId'))); + $qb->andWhere($qb->expr()->in('id', $qb->createFunction($selectSubQuery->getSQL()))); + } else { + $qb->where($qb->expr()->in('id', $qb->createFunction($selectSubQuery->getSQL()))); + } $qb->setParameters([ 'lastContact' => time() - SessionService::SESSION_VALID_TIME, 'documentId' => $documentId, diff --git a/lib/Listeners/AddMissingIndicesListener.php b/lib/Listeners/AddMissingIndicesListener.php new file mode 100644 index 00000000000..dd23d8b1f52 --- /dev/null +++ b/lib/Listeners/AddMissingIndicesListener.php @@ -0,0 +1,43 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Text\Listeners; + +use OCP\DB\Events\AddMissingIndicesEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +/** + * @template-implements IEventListener + */ +class AddMissingIndicesListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof AddMissingIndicesEvent) { + return; + } + + $event->addMissingIndex('text_steps', 'ts_session', ['session_id']); + } +} diff --git a/lib/Migration/Version010000Date20190617184535.php b/lib/Migration/Version010000Date20190617184535.php index aaafc11820b..4596f8caae2 100644 --- a/lib/Migration/Version010000Date20190617184535.php +++ b/lib/Migration/Version010000Date20190617184535.php @@ -130,6 +130,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->setPrimaryKey(['id']); $table->addIndex(['document_id'], 'rd_steps_did_idx'); $table->addIndex(['version'], 'rd_steps_version_idx'); + $table->addIndex(['session_id'], 'ts_session'); } return $schema; }