Problem/Motivation

In #2878438-8: Update {content_revision_tracker} after the most recent (draft) revision is deleted alexpott has noticed that we don't invalidate cache tags when deleting an entity revision. Currently we don't have any support for revision cache tags, but with the ongoing usage of forward/non-default revisions we need to introduce revision cache tags.

Proposed resolution

  • The revision cache tag "entity_type_id:rev:rev_id" has to be invalidated on revision delete.
  • The revision cache tag "entity_type_id:rev:rev_id" has to be invalidated when saving an existing entity revision without creating a new one.
  • When creating a new forward/non-default revision the cache tag "entity_type_id:latest_forward_revision" has to be invalidated in order to invalidate e.g. views that are cached based on a content from the lastest non-default revision.
  • Should we allow the EntityViewBuilder to cache the rendered output of a non-default revisions?

Remaining tasks

Remove the manual views cache invalidation introduced in the test from #2878438: Update {content_revision_tracker} after the most recent (draft) revision is deleted.

User interface changes

API changes

Data model changes

Issue fork drupal-2879244

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hchonov created an issue. See original summary.

berdir’s picture

Can't we just invalidate the main entity cache tag when this happens? We might clear caches that we wouldn't have to, but there are also some interesting special cases, like deleting the only non-default revision and the impact of that (e.g. visibility of the revisions local task)

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.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jibran’s picture

Over in #2730631: Upcast node and node_revision parameters of node revision routes a block is added to the page which shows nid and vid based on the node_revision you are viewing. I had to add max-age 0 because there is no node revision tag I can add to the page.

Also \Drupal\node\Controller\NodeController::revisionShow has unset($page['nodes'][$node->id()]['#cache']); which can be removed if we fix this issue.

berdir’s picture

@jibran: The short answer to that is: No.

The longer answer is that the solution for both of those two things isn't cache tags, it is cache contexts in one case and cache keys in the other.

Cache tags are for invalidation. So the only thing this issue would help with is invalidating cached things, but that doesn't solve either of your problems. And revision cache tags are also only an optimization, those things already have the the node id cache tag, we'd just invalidate things for all revisions of a node.

The block needs cache contexts, because different versions of the same block could exist at the "same" time, without any invalidation happening. I would kind of expect that this does work, because if the block depends on plugin context, then the node it receives should have the route cache context, and that is different for each revision. Will try to have a closer look at that.

And the reason the cache *keys* are unset is because the keys would be the same for all revisions of the node, not the specific one you're looking at. So we could just add a revision id instead of removing it completely right now and it would just work. But the reason we don't do that is that it is most likely not worth to cache, viewing a revision is in almost all scenarios a rare action that only users with access to that do. The chance for a cache hit on a rendered node revision is very low, so we'd just fill up cache space.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan made their first commit to this issue’s fork.

mstrelan’s picture

Status: Active » Needs work
Issue tags: +Needs tests

I agree with @berdir in #2. Have started an MR to do this when revisions are deleted.

Should this be reclassified as a bug? Here are steps to reproduce, there is likely a simpler way to reproduce this though.

  1. Install Drupal with demo_umami profile
  2. Create a view showing content revisions, filtered by "is latest revision", sorted by "revision create time" desc
  3. Add the revision id and moderation state fields to the view
  4. Edit the node at the top of the view, create a new draft revision
  5. Load the view, take node of the revision id and moderation state of the page that was edited
  6. Delete the latest revision, repeat step 5, note it hasn't changed
  7. Clear cache and repeat step 5, note it has changed
berdir’s picture

The current MR is the same as #2945928: Cache is not invalidated when deleting a revision see my comment there, I think we could close this as a duplicate.

I also partially changed my opinion as we already have a cache tag for revisions that we use invalidate in some cases, so things changed a bit since 2017.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

prudloff’s picture

I think we should keep #2945928: Cache is not invalidated when deleting a revision because it has tests and the MR here does not have any.
(We should of course transfer credits.)