dawehner pointed out in #1446932: Improve statistics performance by adding a swappable backend to simplify this.

+++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php
@@ -82,28 +154,64 @@ public function build() {
+      $item = [
+        '#type' => 'link',
+        '#title' => $node->getTitle(),
+        '#url' => $node->urlInfo('canonical'),
+      ];
+      $this->renderer->addCacheableDependency($item, $node);

This could use $node->toLink()->toRenderable()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mallezie created an issue. See original summary.

arunkumark’s picture

Status: Active » Needs review
FileSize
840 bytes

Hi,

As per suggestion in Issue, i have patched to improve performance of Statics block.

timmillwood’s picture

I wonder if we need an updated test for this in \Drupal\statistics\Tests\StatisticsReportsTest::testPopularContentBlock.

Status: Needs review » Needs work

The last submitted patch, 2: build_lisnt_statistics_toRender_2778167_2.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
871 bytes
950 bytes

Great catch :)

But you deleted one line too many, hence the failing test.

(Which ideally would indeed not be necessary, but alas, since class Link implements RenderableInterface and not class Link implements RenderableInterface, CacheableDependencyInterface, that one line is still necessary.)

Pleasantly surprised that Statistics' tests are this complete that they caught this regression! :)

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This ends up being a really small improvement, but it is an improvement. Great work!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed e89abeb and pushed to 8.6.x. Thanks!

  • alexpott committed e89abeb on 8.6.x
    Issue #2778167 by Wim Leers, arunkumark: Build link in Statistics block...

  • catch committed 84e302e on 8.5.x authored by alexpott
    Issue #2778167 by Wim Leers, arunkumark: Build link in Statistics block...

Status: Fixed » Closed (fixed)

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