Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Listener for missing db indices #2527

Merged
merged 6 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]]></description>
<version>25.0.0-alpha3</version>
<version>25.0.0-alpha4</version>
<licence>agpl</licence>
<author>Benjamin Brahmer</author>
<author>Sean Molenaar</author>
Expand Down
6 changes: 3 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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');
Expand Down
32 changes: 32 additions & 0 deletions lib/Listeners/AddMissingIndicesListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Nextcloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Benjamin Brahmer <[email protected]>
* @copyright 2023 Benjamin Brahmer
*/

namespace OCA\News\Listeners;

use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\DB\Events\AddMissingIndicesEvent;

/**
* @template-implements IEventListener<Event|AddMissingIndicesEvent>
*/
class AddMissingIndicesListener implements IEventListener
{
public function handle(Event $event): void
{
if (!$event instanceof AddMissingIndicesEvent) {
return;
}

$event->addMissingIndex('news_feeds', 'news_feeds_deleted_at_index', ['deleted_at']);
}
}
2 changes: 2 additions & 0 deletions lib/Migration/Version140200Date20200824201413.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version150004Date20201009183830.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions lib/Migration/Version150005Date20201009192341.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading