From 3f5b185abecede78f1c2bad7a83c35e9c838ebdb Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Fri, 29 Dec 2023 18:31:15 +0100 Subject: [PATCH 1/6] Add Listener for missing db indices this allows admins to add them via occ. Signed-off-by: Benjamin Brahmer --- CHANGELOG.md | 1 + lib/AppInfo/Application.php | 3 ++ lib/Listeners/AddMissingIndicesListener.php | 32 +++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 lib/Listeners/AddMissingIndicesListener.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f588a8785f..c0ff3d765b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1 # Unreleased ## [25.x.x] ### Changed +- Add DB index for news_feeds.deleted_at (#2526) ### Fixed diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 8bfa09c86c..e8e548c4b2 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -24,6 +24,7 @@ use OCA\News\Search\FeedSearchProvider; use OCA\News\Search\FolderSearchProvider; use OCA\News\Search\ItemSearchProvider; +use OCA\News\Listeners\AddMissingIndicesListener; use OCA\News\Utility\Cache; use OCP\AppFramework\Bootstrap\IBootContext; @@ -34,6 +35,7 @@ use OCA\News\Fetcher\FeedFetcher; use OCA\News\Fetcher\Fetcher; use OCP\User\Events\BeforeUserDeletedEvent; +use OCP\DB\Events\AddMissingIndicesEvent; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -87,6 +89,7 @@ public function register(IRegistrationContext $context): void $context->registerEventListener(BeforeUserDeletedEvent::class, UserDeleteHook::class); + $context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class); // parameters $context->registerParameter('exploreDir', __DIR__ . '/../Explore/feeds'); diff --git a/lib/Listeners/AddMissingIndicesListener.php b/lib/Listeners/AddMissingIndicesListener.php new file mode 100644 index 0000000000..f9e697901c --- /dev/null +++ b/lib/Listeners/AddMissingIndicesListener.php @@ -0,0 +1,32 @@ + + * @copyright 2023 Benjamin Brahmer + */ + + namespace OCA\News\Listeners; + + use OCP\EventDispatcher\Event; + use OCP\EventDispatcher\IEventListener; + use OCP\DB\Events\AddMissingIncidesEvent; + + /** + * @template-implements IEventListener + */ +class AddMissingIndicesListener implements IEventListener +{ + public function handle(Event $event): void + { + if (!$event instanceof AddMissingIncidesEvent) { + return; + } + + $event->addMissingIndex('news_feeds', 'news_feeds_deleted_at_index', ['deleted_at']); + } +} From b9c10d7d84b7250475266317eaf8fdeb6fe738f7 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 30 Dec 2023 10:07:48 +0100 Subject: [PATCH 2/6] php 8.2 deprecated ${} in strings {$var} is a working alternative Signed-off-by: Benjamin Brahmer --- lib/Migration/Version150004Date20201009183830.php | 2 +- lib/Migration/Version150005Date20201009192341.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Migration/Version150004Date20201009183830.php b/lib/Migration/Version150004Date20201009183830.php index 635d8d5920..b587d8ad97 100644 --- a/lib/Migration/Version150004Date20201009183830.php +++ b/lib/Migration/Version150004Date20201009183830.php @@ -72,7 +72,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $item_name = $this->connection->getQueryBuilder()->getTableName('news_items'); $feed_name = $this->connection->getQueryBuilder()->getTableName('news_feeds'); - $items_query = "DELETE FROM ${item_name} WHERE ${item_name}.`feed_id` NOT IN (SELECT DISTINCT id FROM ${feed_name})"; + $items_query = "DELETE FROM {$item_name} WHERE {$item_name}.`feed_id` NOT IN (SELECT DISTINCT id FROM {$feed_name})"; $this->connection->executeQuery($items_query); } } diff --git a/lib/Migration/Version150005Date20201009192341.php b/lib/Migration/Version150005Date20201009192341.php index 7d739603b4..bcb4195d57 100644 --- a/lib/Migration/Version150005Date20201009192341.php +++ b/lib/Migration/Version150005Date20201009192341.php @@ -41,13 +41,13 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ $feed_name = $this->connection->getQueryBuilder()->getTableName('news_feeds'); $folder_name = $this->connection->getQueryBuilder()->getTableName('news_folders'); - $items_query = "DELETE FROM ${feed_name} WHERE ${feed_name}.`folder_id` NOT IN (SELECT DISTINCT id FROM ${folder_name}) AND ${feed_name}.`folder_id` IS NOT NULL"; + $items_query = "DELETE FROM {$feed_name} WHERE {$feed_name}.`folder_id` NOT IN (SELECT DISTINCT id FROM {$folder_name}) AND {$feed_name}.`folder_id` IS NOT NULL"; $this->connection->executeQuery($items_query); $item_name = $this->connection->getQueryBuilder()->getTableName('news_items'); $feed_name = $this->connection->getQueryBuilder()->getTableName('news_feeds'); - $items_query = "DELETE FROM ${item_name} WHERE ${item_name}.`feed_id` NOT IN (SELECT DISTINCT id FROM ${feed_name})"; + $items_query = "DELETE FROM {$item_name} WHERE {$item_name}.`feed_id` NOT IN (SELECT DISTINCT id FROM {$feed_name})"; $this->connection->executeQuery($items_query); } From 7c294a0aa532bff384639f5b3182b0917a50616e Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 30 Dec 2023 10:11:20 +0100 Subject: [PATCH 3/6] adjust existing migration Signed-off-by: Benjamin Brahmer --- lib/Migration/Version140200Date20200824201413.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Migration/Version140200Date20200824201413.php b/lib/Migration/Version140200Date20200824201413.php index 8c7298f6ea..2663339c50 100644 --- a/lib/Migration/Version140200Date20200824201413.php +++ b/lib/Migration/Version140200Date20200824201413.php @@ -181,6 +181,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addIndex(['user_id'], 'news_feeds_user_id_index'); $table->addIndex(['folder_id'], 'news_feeds_folder_id_index'); $table->addIndex(['url_hash'], 'news_feeds_url_hash_index'); + //added with news 25.x + $table->addIndex(['deleted_at'], 'news_feeds_deleted_at_index'); } if (!$schema->hasTable('news_items')) { From b8aa4eb876529b08fb55f6c5211f886bd3bb96f3 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 30 Dec 2023 10:37:35 +0100 Subject: [PATCH 4/6] change order of droping tables, constraints Signed-off-by: Benjamin Brahmer --- docs/install.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/install.md b/docs/install.md index 50bd69ce05..6cfde70ca9 100644 --- a/docs/install.md +++ b/docs/install.md @@ -123,9 +123,9 @@ Connect to your DB and execute the commands. Don't forget to switch to the right For example in mysql: `use nextcloud;` ```sql -DROP TABLE oc_news_folders; -DROP TABLE oc_news_feeds; DROP TABLE oc_news_items; +DROP TABLE oc_news_feeds; +DROP TABLE oc_news_folders; ``` Then we remove the traces in the migrations table. @@ -149,4 +149,4 @@ DELETE FROM oc_jobs WHERE class='OCA\\News\\Cron\\Updater'; DELETE FROM oc_jobs WHERE argument='["OCA\\\\News\\\\Cron\\\\Updater","run"]'; ``` -Now nothing is left from News in your nextcloud installation. +Now nothing is left from News in your Nextcloud installation. From 848e77d7603e4ad9397ddbc2ef702480967d4957 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 30 Dec 2023 10:43:52 +0100 Subject: [PATCH 5/6] bump version Signed-off-by: Benjamin Brahmer --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index cc0b59b655..860c877dd0 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -21,7 +21,7 @@ Create a [feature request](https://github.com/nextcloud/news/discussions/new) Report a [feed issue](https://github.com/nextcloud/news/discussions/new) ]]> - 25.0.0-alpha3 + 25.0.0-alpha4 agpl Benjamin Brahmer Sean Molenaar From 8a611eddd3e46694848cdec6fbb222559c75c501 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 30 Dec 2023 10:52:31 +0100 Subject: [PATCH 6/6] fix typo Signed-off-by: Benjamin Brahmer --- lib/Listeners/AddMissingIndicesListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/AddMissingIndicesListener.php b/lib/Listeners/AddMissingIndicesListener.php index f9e697901c..92faf24049 100644 --- a/lib/Listeners/AddMissingIndicesListener.php +++ b/lib/Listeners/AddMissingIndicesListener.php @@ -14,7 +14,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; - use OCP\DB\Events\AddMissingIncidesEvent; + use OCP\DB\Events\AddMissingIndicesEvent; /** * @template-implements IEventListener @@ -23,7 +23,7 @@ class AddMissingIndicesListener implements IEventListener { public function handle(Event $event): void { - if (!$event instanceof AddMissingIncidesEvent) { + if (!$event instanceof AddMissingIndicesEvent) { return; }