Followup from #1930274-45: Convert aggregator processors and parsers to plugins

Replace db_* calls for aggregator feeds and items with the entity storage controller/ entity_query equilavent

CommentFileSizeAuthor
#67 1957312-drupal-aggregator_entity_storage-67.patch28.39 KBParisLiakos
#65 1957312-drupal-aggregator_entity_storage-65.patch28.37 KBParisLiakos
#64 1957312-drupal-aggregator_entity_storage-64.patch28.36 KBParisLiakos
#63 interdiff.txt2.04 KBParisLiakos
#63 1957312-drupal-aggregator_entity_storage-63.patch28.35 KBParisLiakos
#62 1957312-drupal-aggregator_entity_storage-62.patch27.26 KBParisLiakos
#59 1957312-drupal-aggregator_entity_storage-59.patch27.24 KBParisLiakos
#58 interdiff.txt3.58 KBParisLiakos
#58 1957312-drupal-aggregator_entity_storage-58.patch26.66 KBParisLiakos
#57 1957312-drupal-aggregator_entity_storage-57.patch26.63 KBParisLiakos
#56 interdiff.txt644 bytesParisLiakos
#56 1957312-drupal-aggregator_entity_storage-56.patch26.63 KBParisLiakos
#54 interdiff.txt11.53 KBParisLiakos
#54 1957312-drupal-aggregator_entity_storage-54.patch26.63 KBParisLiakos
#50 interdiff.txt3.14 KBpeximo
#49 1957312-drupal-aggregator_entity_storage-49.patch22.36 KBpeximo
#47 interdiff.txt4.19 KBpeximo
#47 1957312-drupal-aggregator_entity_storage-47.patch21.9 KBpeximo
#44 1957312-drupal-aggregator_entity_storage-44.patch20.73 KBpeximo
#34 1957312-drupal-aggregator_entity_storage-34.patch22.49 KBpeximo
#32 1957312-drupal-aggregator_entity_storage-32.patch19.17 KBpeximo
#29 1957312-drupal-aggregator_entity_storage-29.patch19.49 KBpeximo
#29 interdiff.txt11.98 KBpeximo
#25 1957312-drupal-aggregator_entity_storage-25.patch14.91 KBpeximo
#25 interdiff.txt9.12 KBpeximo
#19 interdiff.txt7.5 KBDésiré
#19 1957312-drupal-aggregator_entity_storage-19.patch9.95 KBDésiré
#15 drupal-aggregator_entity_storage-1957312-15.patch2.67 KBDésiré
#10 drupal-aggregator_entity_storage-1957312-9.patch5.36 KBParisLiakos
#10 interdiff.txt1.5 KBParisLiakos
#3 drupal-aggregator_entity_storage-1957312-3.patch5.41 KBParisLiakos
#1 drupal-aggregator_entity_storage-1957312-1.patch5.46 KBParisLiakos
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ParisLiakos’s picture

Status: Active » Needs review
FileSize
5.46 KB

i have no clue what to do with

  $result = db_query('SELECT fid FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', array(
    ':time' => REQUEST_TIME,
    ':never' => AGGREGATOR_CLEAR_NEVER
  ));

The other change in aggregator_cron() could use some benchmarking?
see #1930274-53: Convert aggregator processors and parsers to plugins

Status: Needs review » Needs work

The last submitted patch, drupal-aggregator_entity_storage-1957312-1.patch, failed testing.

ParisLiakos’s picture

ParisLiakos’s picture

Status: Needs work » Needs review

sigh..status

Status: Needs review » Needs work

The last submitted patch, drupal-aggregator_entity_storage-1957312-3.patch, failed testing.

ParisLiakos’s picture

Status: Needs work » Needs review

EntityFilteringThemeTest.php line 122
random failure?

#3: drupal-aggregator_entity_storage-1957312-3.patch queued for re-testing.

twistor’s picture

Looks good so far.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.phpundefined
@@ -150,9 +150,9 @@ public function process(Feed $feed) {
   public function remove(Feed $feed) {
-    $iids = Database::getConnection()->query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchCol();
-    if ($iids) {
-      entity_delete_multiple('aggregator_item', $iids);
+    $items = entity_load_multiple_by_properties('aggregator_item', array('fid' => $feed->id()));
+    foreach ($items as $item) {
+      $item->delete();
     }
     // @todo This should be moved out to caller with a different message maybe.

This should still use entity_delete_multiple().

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.phpundefined
@@ -169,13 +169,15 @@ public function postProcess(Feed $feed) {
-        entity_delete_multiple('aggregator_item', $iids);
+      $result = entity_query('aggregator_item')
+        ->condition('fid', $feed->id())
+        ->condition('timestamp', $age, '<')
+        ->execute();
+      if ($result) {
+        $items = entity_load_multiple('aggregator_item', $result);
+        foreach ($items as $item) {
+          $item->delete();
+        }
       }

entity_delete_multiple().

ParisLiakos’s picture

entity_delete_multiple() needs the id array..so i looped the items instead...hmm but now that you say so, i think entity_load_multiple() returns the array keyed by ids so i could use array_keys i think, will check later

twistor’s picture

It takes the same arguments as entity_load_multiple().

ParisLiakos’s picture

this is a lot better, you are right:)

andypost’s picture

Status: Needs review » Needs work
+++ b/core/modules/aggregator/aggregator.moduleundefined
@@ -317,10 +317,16 @@ function aggregator_cron() {
+  $result = entity_query('aggregator_feed')

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.phpundefined
@@ -30,10 +30,17 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
+    $result = entity_query('aggregator_feed')

@@ -42,11 +49,15 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
+    $result = entity_query('aggregator_feed')

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.phpundefined
@@ -150,9 +150,11 @@ public function process(Feed $feed) {
+    $result = entity_query('aggregator_item')

@@ -169,13 +171,12 @@ public function postProcess(Feed $feed) {
+      $result = entity_query('aggregator_item')

This needs reroll - #1957148: Replace entity_query() with Drupal::entityQuery()

twistor’s picture

There's 2 ways we can fix the hook_cron() query.

  1. Add expression support to entity_query().
  2. Add a next, REQUEST_TIME + refresh, column in {aggregator_feed}.

We could change the last column to next. Most things that last was needed for could be changed to next - refresh, but then we wouldn't be accurately reporting the last run time if the refresh time changed.

plach’s picture

Désiré’s picture

Assigned: Unassigned » Désiré
Désiré’s picture

Now I'm just rerolled the patch, without the core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php modifications, since it was removed.

But there are other new SQL queries in the code which should be changed too.

Put it to needs review only for testing the rerolled patch.

Désiré’s picture

Status: Needs work » Needs review
ParisLiakos’s picture

  1. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php
    @@ -190,9 +190,11 @@ public function process(Feed $feed) {
    +    $result = \Drupal::entityQuery('aggregator_item')
    
    @@ -209,13 +211,12 @@ public function postProcess(Feed $feed) {
    +      $result = \Drupal::entityQuery('aggregator_item')
    

    we can now inject stuff to plugins so entity query should be injected.

  2. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php
    @@ -190,9 +190,11 @@ public function process(Feed $feed) {
    +      entity_delete_multiple('aggregator_item', $result);
    
    @@ -209,13 +211,12 @@ public function postProcess(Feed $feed) {
    +        entity_delete_multiple('aggregator_item', $result);
    

    and the item storage controller

There is also one more query in \Drupal\aggregator\Plugin\Block\AggregatorFeedBlock::build() to get rid of and one in \Drupal\aggregator\Controller\AggregatorController::adminOverview()

Désiré’s picture

Status: Needs review » Needs work
Désiré’s picture

Status: Needs work » Needs review
FileSize
9.95 KB
7.5 KB

The two remaining query are replaced.
I think the feeds category query could be not replaced since the feeds categories aren't entities.

I'm a kind of new with D8 so can you help me, how can I do these things with dependency injection?

Status: Needs review » Needs work

The last submitted patch, 1957312-drupal-aggregator_entity_storage-19.patch, failed testing.

ParisLiakos’s picture

  1. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php
    @@ -173,33 +173,42 @@ public function feedRefresh(FeedInterface $aggregator_feed, Request $request) {
    +    $result = \Drupal::entityQuery('aggregator_feed')
    +      ->execute();
    ...
    +    $feeds = entity_load_multiple('aggregator_feed', $result);
    

    you dont have to use the entityQuery at all. i think just calling entity_load_mutiple without the second parameter, gives you all the entities

  2. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
    @@ -170,6 +170,16 @@ public function label($langcode = NULL) {
    +  public function getItemCount() {
    

    this method should be moved to the FeedStorageController instead (and also added to its interface)

  3. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
    @@ -131,31 +131,33 @@ public function blockSubmit($form, &$form_state) {
    +      $result = \Drupal::entityQuery('aggregator_item')
    

    to inject this:

    in the class::create() method, add as parameter $container->get('entity.query')->get('aggregator_item') to the new static() call.

    This will pass it to the class constructor as additional argument, where you will take it and store it to a property. eg $this->itemEntityQuery.

    then instead of using \Drupal::entityQuery('aggregator_item') use the property instead;)

  4. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
    @@ -131,31 +131,33 @@ public function blockSubmit($form, &$form_state) {
    +      $items = entity_load_multiple('aggregator_item', $result);
    

    same for this but in the create method you will add

    $container->get('entity.manager')->getStorageController('aggregator_item')

  5. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
    @@ -131,31 +131,33 @@ public function blockSubmit($form, &$form_state) {
    -      $result = $this->connection->queryRange("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $this->configuration['block_count'], array(':fid' => $feed->id()));
    +      $result = \Drupal::entityQuery('aggregator_item')
    +        ->condition('fid', $feed->id())
    +        ->range(0, $this->configuration['block_count'])
    +        ->execute();
    

    we should add the ORDER BY part in the entity query too

plach’s picture

Are you still working on this? Otherwise tomorrow we should be able to bring it forward at the Prague extended sprint.

plach’s picture

peximo’s picture

Assigned: Désiré » peximo

Ok I work on this.

peximo’s picture

Ok, modified as suggested.
Some considerations:
1. aggregator_save_category() seems never called: we need to remove this function? Or we need to convert it anyway?
2. aggregator_page_opml() is deprecated, we need to convert it anyway?
3. [12] @chx has suggested to first move the logic in the storage controller and than open a follow up issue.

peximo’s picture

Status: Needs work » Needs review

Sorry wrong status.

ParisLiakos’s picture

  1. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php
    @@ -173,33 +173,42 @@ public function feedRefresh(FeedInterface $aggregator_feed, Request $request) {
    +    $feeds = entity_load_multiple('aggregator_feed');
    ...
    +    $storage_controller = \Drupal::entityManager()->getStorageController('aggregator_feed');
    

    lets retrieve the storage controller before the entity_load_multiple call, and use it there too.
    also it should be retrieved with $this->entityManager()

  2. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageController.php
    @@ -62,4 +62,21 @@ public function deleteCategories(array $feeds) {
    +  public function getItemCount(Feed $feed) {
    
    +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageControllerInterface.php
    @@ -42,4 +42,20 @@ public function saveCategories(Feed $feed, array $categories);
    +  public function getItemCount(Feed $feed);
    

    should be typehinted with FeedInterface

  3. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageController.php
    @@ -62,4 +62,21 @@ public function deleteCategories(array $feeds) {
    +  public function getFeedsToRefresh() {
    +    return $this->database->query('SELECT fid FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', array(
    ...
    +    ));
    

    so this actually retrieves the feed IDs not the whole feed objects.
    So i would say, name it getFeedIdsToRefresh().

    Also it shouldnt return the query, but rather it should fetchCol() first

  4. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
    @@ -130,32 +149,36 @@ public function blockSubmit($form, &$form_state) {
    -    if ($feed = $this->storageController->load($this->configuration['feed'])) {
    ...
    +    if ($feed = $this->itemStorage->load($this->configuration['feed'])) {
    

    i think this should be feedStroage not itemStorage

  5. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
    @@ -130,32 +149,36 @@ public function blockSubmit($form, &$form_state) {
    +      $items = entity_load_multiple('aggregator_item', $result);
    

    this should also use the itemStorage to load and not the procedural function

  6. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php
    @@ -190,9 +190,11 @@ public function process(Feed $feed) {
    +    $result = \Drupal::entityQuery('aggregator_item')
    ...
    +      entity_delete_multiple('aggregator_item', $result);
    
    @@ -209,13 +211,12 @@ public function postProcess(Feed $feed) {
    +      $result = \Drupal::entityQuery('aggregator_item')
    ...
    +        entity_delete_multiple('aggregator_item', $result);
    

    lets inject the entity_query and the item storage here as described in #21

Status: Needs review » Needs work

The last submitted patch, 1957312-drupal-aggregator_entity_storage-25.patch, failed testing.

peximo’s picture

Status: Needs work » Needs review
FileSize
11.98 KB
19.49 KB

Rerolled and modified as suggested, needs work because some tests fail.

Status: Needs review » Needs work

The last submitted patch, 1957312-drupal-aggregator_entity_storage-29.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updated issue summary

plach’s picture

peximo’s picture

Status: Needs work » Needs review
FileSize
19.17 KB

Rerolled with some adjustment.

Status: Needs review » Needs work

The last submitted patch, 32: 1957312-drupal-aggregator_entity_storage-32.patch, failed testing.

peximo’s picture

Status: Needs work » Needs review
FileSize
22.49 KB

Rerolled; the work should be finished.

Status: Needs review » Needs work

The last submitted patch, 34: 1957312-drupal-aggregator_entity_storage-34.patch, failed testing.

The last submitted patch, 34: 1957312-drupal-aggregator_entity_storage-34.patch, failed testing.

plach’s picture

Status: Needs work » Needs review
ParisLiakos’s picture

Status: Needs review » Needs work

looks great to me, thanks!

Just one thing

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php
@@ -190,9 +212,12 @@ public function process(Feed $feed) {
+    $result = $this->entityQuery->get('aggregator_item')
+      ->condition('fid', $feed->id())
+      ->execute();

we should use the loadByFeed() method in ItemStorageController..By making the method there to default to NULL $limit rather than 20.So one can use it to fetch all items too.. (Change that would affect loadByCategory() too)

and also a reroll

plach’s picture

@peximo

Are you still working on this? Otherwise unassign it so that someone else can pick it up :)

plach’s picture

@peximo:

Are you still working on this? Otherwise unassign it so that someone else can pick it up :)

Berdir’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 34: 1957312-drupal-aggregator_entity_storage-34.patch, failed testing.

peximo’s picture

@plach:
I can work on it a bit in the coming weekend.

peximo’s picture

Status: Needs work » Needs review
FileSize
20.73 KB

Rerolled, I have changed as suggested in #38.
@ParisLiakos: loadByCategory() is gone, we need to change also loadAll()?

Status: Needs review » Needs work

The last submitted patch, 44: 1957312-drupal-aggregator_entity_storage-44.patch, failed testing.

ParisLiakos’s picture

@peximo Yes exactly:) thanks for rolling this

peximo’s picture

Status: Needs work » Needs review
FileSize
21.9 KB
4.19 KB

Rerolled with some adjustments; if green I hope the work is done.

ParisLiakos’s picture

Status: Needs review » Needs work

Thanks! Looks almost done.
Just a few docs issues i could find

  1. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageControllerInterface.php
    @@ -26,4 +26,19 @@
    +  /**
    +   * Returns the fids of feed that need to be refreshed.
    

    Probably feed here should be plural. ie feeds

  2. +++ b/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php
    @@ -23,7 +23,7 @@ class ItemStorageController extends FieldableDatabaseStorageController implement
    -  public function loadAll($limit = 20) {
    +  public function loadAll($limit = FALSE) {
    
    @@ -33,7 +33,7 @@ public function loadAll($limit = 20) {
    -  public function loadByFeed($fid, $limit = 20) {
    +  public function loadByFeed($fid, $limit = FALSE) {
    

    it should default to NULL, not FALSE :)

  3. ItemStorageControllerInterface::loadAll() docblock still says it defaults to 20
peximo’s picture

Status: Needs work » Needs review
FileSize
22.36 KB

Ok, I removed also a non existent default limit in executeFeedItemQuery() docblock.

peximo’s picture

FileSize
3.14 KB

sorry I forgot the intediff.

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

catch’s picture

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedStorageController.php
@@ -32,4 +32,20 @@ public function getFeedDuplicates(FeedInterface $feed) {
+  }

Can't use entityQuery here?

ParisLiakos’s picture

Assigned: peximo » ParisLiakos
Status: Reviewed & tested by the community » Needs work

ah, yes, good point. there is a count() method in QueryInterface.
also i found a couple forgotten spots that need to be converted as well

ParisLiakos’s picture

Status: Needs work » Needs review
FileSize
26.63 KB
11.53 KB

yes, its a lot better now:)

getItemCount should be in the Item storage controller not the Feed one.
also got rid the database from aggregator controller

The last submitted patch, 54: 1957312-drupal-aggregator_entity_storage-54.patch, failed testing.

ParisLiakos’s picture

ParisLiakos’s picture

Assigned: ParisLiakos » Unassigned
FileSize
26.63 KB

reroll

ParisLiakos’s picture

lets also use the methods now that #2028037: Expand FeedInterface with methods is in.
this should be good to go now

ParisLiakos’s picture

Reroll plus some docs fixes/additions

jibran’s picture

Status: Needs review » Needs work

The last submitted patch, 59: 1957312-drupal-aggregator_entity_storage-59.patch, failed testing.

ParisLiakos’s picture

Status: Needs work » Needs review
FileSize
27.26 KB

reroll

ParisLiakos’s picture

and of course, we dont need that hack anymore:)

ParisLiakos’s picture

one more reroll

ParisLiakos’s picture

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for sticking with it. I think we are done here.

ParisLiakos’s picture

yay, thanks!
but aggregator goes faaaast those days:D

rerolls++

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 67: 1957312-drupal-aggregator_entity_storage-67.patch, failed testing.

ParisLiakos’s picture

Status: Needs work » Needs review
ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Nice work!

Committed and pushed to 8.x. Thanks!

  • Commit ac9ab3b on 8.x by webchick:
    Issue #1957312 by ParisLiakos, peximo, Désiré: Use the entity storage...
chx’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.