Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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()
Comment | File | Size | Author |
---|---|---|---|
#8 | 2778167-8.patch | 950 bytes | Wim Leers |
Comments
Comment #2
arunkumarkHi,
As per suggestion in Issue, i have patched to improve performance of Statics block.
Comment #3
timmillwoodI wonder if we need an updated test for this in
\Drupal\statistics\Tests\StatisticsReportsTest::testPopularContentBlock
.Comment #8
Wim LeersGreat 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 notclass Link implements RenderableInterface, CacheableDependencyInterface
, that one line is still necessary.)Pleasantly surprised that Statistics' tests are this complete that they caught this regression! :)
Comment #9
borisson_This ends up being a really small improvement, but it is an improvement. Great work!
Comment #10
alexpottCommitted e89abeb and pushed to 8.6.x. Thanks!