The latest_revision ViewsFilter has poor performance

Created on 5 March 2018, over 6 years ago
Updated 23 January 2024, 10 months ago

Problem/Motivation

This issue is in relation to https://www.drupal.org/project/drupal/issues/2865579 and the removal of the revision tracker table in favor of a simple SQL query to return latest revision. While this change makes sense it seems to have a very negative impact on larger sites that have very large revision tables.

A client I'm currently working with has recently made the update to content moderation from workbench moderation. With workbench moderation we previously were able to return the latest revision of nodes to editors through a view. Now after updating to content moderation, the same views configurations will completely lock up the db. Instead of hitting a much smaller latest revision table we have to now query a much larger revisions table.

It seems without that revision tracker table our only real course of action will be to destroy revision history to make the revision tables as small as possible and hopefully improve performance that way. While it may not be necessary to maintain a complete revision history it still seems that there should be a better solution to this issue though.

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
Content moderation 

Last updated 1 day ago

Created by

🇺🇸United States jecunningham2281

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • VDC

    Related to the Views in Drupal Core initiative.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Reading the comments #29 appears to be addressed in #30.

    As a bug believe this will need it's own test case to show the issue is being resolved.

    Also posting to #testing to verify that.

  • 🇧🇾Belarus dewalt

    I propose also to add new index on node_field_revision table, in my case it extremely increase a performance:
    - revision_translation_affected
    - nid
    - vid

    Looks like temporary table constructions in $subquery isn't cached by MariaDB engine. We have match content and more that 100k revisions. Having a dashboard with 4 node revision views (each use "Is Latest Translation Affected Revision" filter) I have the next times of the page render (I make `drush cr` before each load):

    Core: 7m 15s
    Core+index: 40s
    Patch #25: 3m 40s
    Patch #25+index: 5s!!!

  • Status changed to Needs review about 1 year ago
  • 🇬🇧United Kingdom catch

    @smustgrave we can't add tests for query performance, if there's existing test coverage of the latest_revision filter that should be sufficient. Untagging for 'needs tests' but we should verify whether existing tests exist.

    @dewalt that seems like a good idea, but should be its own issue, since it'll need an upgrade path etc. Could you open the issue?

    Moving back to needs review.

  • last update about 1 year ago
    30,136 pass
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Thanks @catch for cleaning that up.

    Opened https://www.drupal.org/project/drupal/issues/3386159 📌 Add new index to node_field_revision Active for #33

    #30 is all green but issue summary think could use some love so tagging for that. Proposed solution mainly

  • Status changed to Needs review about 1 year ago
  • 🇬🇧United Kingdom catch

    @smustgrave did you check whether there is existing test coverage of the latest_revision filter?

  • Status changed to Needs work about 1 year ago
  • 🇬🇧United Kingdom catch

    Sorry back to needs work.

  • 🇨🇦Canada joseph.olstad

    Drupal\Tests\content_moderation\Unit\LatestRevisionCheckTest
    Drupal\Tests\Core\Enhancer\EntityRevisionRouteEnhancerTest
    Drupal\Tests\Core\ParamConverter\EntityRevisionParamConverte
    Drupal\Tests\migrate\Unit\destination\EntityRevisionTest
    Drupal\Tests\node\Unit\Plugin\views\field\RevisionLinkTest
    Drupal\Tests\node\Unit\Plugin\views\field\RevisionLinkDelete
    Drupal\Tests\node\Unit\Plugin\views\field\RevisionLinkRevert
    Drupal\Tests\block_content\Kernel\Views\RevisionRelationship
    Drupal\Tests\book\Kernel\BookPendingRevisionTest
    Drupal\Tests\block_content\Kernel\Views\RevisionUserTest
    Drupal\Tests\content_moderation\Kernel\DefaultRevisionStateTest
    Drupal\KernelTests\Core\Entity\ContentEntityNonRevisionableF
    Drupal\KernelTests\Core\Entity\EntityNonRevisionableTranslat
    Drupal\KernelTests\Core\Entity\EntityRevisionsTest
    Drupal\KernelTests\Core\Entity\EntityRevisionTranslationTest
    Drupal\KernelTests\Core\Entity\RevisionableContentEntityBase
    Drupal\KernelTests\Core\Entity\RevisionRouteProviderTest
    Drupal\Tests\jsonapi\Kernel\Revisions\VersionNegotiatorTest
    Drupal\Tests\media\Kernel\Views\RevisionUserTest
    Drupal\Tests\migrate\Kernel\Plugin\EntityRevisionTest
    Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeRevisionTest
    Drupal\Tests\node\Kernel\Views\ArgumentNodeRevisionIdTest
    Drupal\Tests\node\Kernel\Views\FilterUidRevisionTest
    Drupal\Tests\node\Kernel\Views\ArgumentUidRevisionTest
    Drupal\Tests\node\Kernel\Views\RevisionRelationshipsTest
    Drupal\Tests\node\Kernel\Views\RevisionUidTest
    Drupal\Tests\node\Kernel\Migrate\d7\MigrateNodeRevisionTest
    Drupal\Tests\taxonomy\Kernel\PendingRevisionTest
    Drupal\Tests\node\Kernel\Views\RevisionCreateTimestampTest
    Drupal\Tests\views\Kernel\Entity\LatestRevisionFilterTest
    Drupal\Tests\block_content\Functional\BlockContentRevisionDe
    Drupal\Tests\block_content\Functional\BlockContentRevisionsT
    Drupal\Tests\block_content\Functional\BlockContentRevisionRe
    Drupal\Tests\block_content\Functional\BlockContentRevisionVe
    Drupal\FunctionalTests\Entity\RevisionRouteProviderTest
    Drupal\FunctionalTests\Entity\RevisionViewTest
    Drupal\Tests\system\Functional\Entity\EntityRevisionsTest
    Drupal\Tests\file\Functional\FileFieldRevisionTest
    Drupal\FunctionalTests\Entity\RevisionDeleteFormTest
    Drupal\FunctionalTests\Entity\RevisionRevertFormTest
    Drupal\FunctionalTests\Entity\RevisionVersionHistoryTest
    Drupal\Tests\views\Functional\Update\ViewsFixRevisionIdUpdat
    Drupal\Tests\media\Functional\MediaRevisionTest
    Drupal\Tests\node\Functional\NodeRevisionsAllTest
    Drupal\Tests\node\Functional\NodeRevisionsUiBypassAccessTest
    Drupal\Tests\node\Functional\NodeRevisionsTest
    Drupal\Tests\node\Functional\NodeRevisionsUiTest
    Drupal\Tests\node\Functional\Views\Wizard\NodeRevisionWizard
    Drupal\Tests\node\Functional\Views\RevisionLinkTest
    Drupal\Tests\views\Functional\Wizard\EntityTestRevisionTes

  • Status changed to RTBC about 1 year ago
  • 🇨🇦Canada joseph.olstad

    yes there is coverage

    Drupal\Tests\views\Kernel\Entity\LatestRevisionFilterTest

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,473 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,473 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,477 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,477 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,482 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,482 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    1:54
    59:09
    Running
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Build Successful
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,642 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,643 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,643 pass
    • catch committed 7d0cc8d0 on 11.x
      Issue #2949939 by azinck, cgoffin, AlexKirienko, Grimreaper, SpadXIII,...
  • Status changed to Fixed about 1 year ago
  • 🇬🇧United Kingdom catch

    Committed/pushed to 11.x, thanks!

    This could theoretically break some hook_query_alter() implementations, so not backporting to 10.1.x. 10.2.x will be out in a couple of months and include this fix.

  • 🇨🇦Canada joseph.olstad

    Thanks @catch

    I did a quick grep through the entire contrib space

    Only 15 handful of contrib modules using hook_query_alter() and likely very few if any related to the latest_revision Views Filter. I doubt that any of them would be.

    bene_event
    clockify_report
    cloudwords
    commerce_cart
    communities_view
    community_builder
    dow_jones_search_clone
    entity_query_alter
    fullcalendar
    ga_reports
    google_appliance
    image_export_import
    local_translation
    multiversion
    nbox

    I'm guessing a very small chance of impact to contrib but possibly custom projects , yet again, very small percentage if any. Way more benefits than risk here.

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

  • Status changed to Fixed 10 months ago
  • 🇺🇸United States jakegibs617

    After upgrading core from 10.1.5 to 10.2.2 this patch stopped working:
    https://www.drupal.org/files/issues/2021-07-27/drupal-views_filter_lates...

    and tested this one, but this also is not applying for me.
    Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2022-12-16/drupal-views_filter_lates...

  • 🇨🇦Canada joseph.olstad

    @jakegibs617
    you do not need this patch, it's already included in 10.2.2

Production build 0.71.5 2024