Switching workspaces shouldn't clear the persistent entity cache

Created on 27 June 2025, 2 months ago

Problem/Motivation

πŸ› Entity queries for latest revisions should return the latest workspace-specific revisions Postponed: needs info introduced a performance regression: the persistent entity cache is cleared when switching workspaces because that issue needed to reset the static cache for the latest revision IDs.

Steps to reproduce

- enable the Workspaces module
- create a node and view it
- navigate away from the node view page, activate a workspace and check the cache_entity table -> there are no entries for that node

Proposed resolution

Change ContentEntityStorageBase to store the latest revision IDs in memory cache, so they can be easily cleared from \Drupal\workspaces\WorkspaceManager::doSwitchWorkspace().

An additional performance improvement is to ensure that WorkspaceManager::executeInWorkspace() and WorkspaceManager::executeOutsideWorkspace() are not switching workspaces unnecessarily.

Remaining tasks

Review.

User interface changes

Nope.

Introduced terminology

N/A.

API changes

Nope.

Data model changes

Nope.

Release notes snippet

N/A

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

workspaces.module

Created by

πŸ‡·πŸ‡΄Romania amateescu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @amateescu
  • Pipeline finished with Success
    2 months ago
    Total: 1443s
    #532948
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Ran test-only job here https://git.drupalcode.org/issue/drupal-3532741/-/jobs/5695770 and got

    1) Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest::testSwitchingWorkspaces
    Failed asserting that false is not false.
    /builds/issue/drupal-3532741/core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php:82
    FAILURES!
    Tests: 3, Assertions: 40, Failures: 1, PHPUnit Deprecations: 4.
    

    Leaning on the tests but locally workspaces seems to be working fine. Created 3, switched back n forth and tested basic functionality.

    Any concern with removing protected variable $latestRevisionIds in contrib or custom modules?

  • πŸ‡·πŸ‡΄Romania amateescu

    Well.. that's very much internal to the content entity storage and I don't really see a reason for outside code/storage overrides to do something with it.

    The alternative would be to add a new method specifically for clearing it, but I don't think that's preferable to the current approach from the MR. Core committers can decide I guess :)

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Fair, that was my only question.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Overall I think the approach looks fine but should we try to use https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Dependenc... to deprecate the property - not with a bc layer just to warn any code trying to access it it's useless now?

  • Pipeline finished with Failed
    about 2 months ago
    Total: 406s
    #543947
  • πŸ‡·πŸ‡΄Romania amateescu

    While looking into @catch's suggestion and realizing that we can't use DeprecatedServicePropertyTrait because that's specific to variables that store services (objects), I figured out that we can actually provide a proper deprecation strategy for this. Wrote a CR as well.

    Ready for reviews again :)

  • Pipeline finished with Failed
    about 2 months ago
    Total: 410s
    #543963
  • Pipeline finished with Failed
    about 1 month ago
    Total: 3560s
    #565569
  • Pipeline finished with Failed
    28 days ago
    #568144
  • Pipeline finished with Success
    28 days ago
    #568152
  • Pipeline finished with Success
    28 days ago
    #568175
Production build 0.71.5 2024