Orphan Purger not triggered when deleting revisions

Created on 20 September 2023, over 1 year ago

Problem/Motivation

When a single revision is deleted, the orphan entities associated with that revision are not deleted from the entity track. This should be triggered when a revision is deleted to ensure that the orphan entities from that revision are also deleted and added to the queue for deletion. This issue specifically pertains to the case of paragraphs.

Steps to reproduce

1) Track an entity.
2) Delete a revision from that entity.
3) Notice that the revision deletion does not trigger the purge queue.

Proposed resolution

Add a hook for the entity revision delete functionality.

Feature request
Status

Needs review

Version

1.10

Component

Code

Created by

🇳🇱Netherlands Remco Hoeneveld

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

Merge Requests

Comments & Activities

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    39 pass
  • Issue created by @Remco Hoeneveld
  • 🇨🇭Switzerland berdir Switzerland

    A test would be useful to demonstrate this, but looks sensible and simple enough.

  • First commit to issue fork.
  • Pipeline finished with Success
    2 months ago
    Total: 147s
    #332459
  • Pipeline finished with Success
    2 months ago
    Total: 153s
    #333579
  • Pipeline finished with Canceled
    2 months ago
    Total: 151s
    #333586
  • Pipeline finished with Canceled
    2 months ago
    Total: 148s
    #333588
  • Pipeline finished with Canceled
    2 months ago
    Total: 132s
    #333589
  • Pipeline finished with Success
    2 months ago
    Total: 188s
    #333590
  • 🇫🇷France mably

    Created an MR based on Remco Hoeneveld patch to allowing to check if a entity orphan up to the root of the composite hierarchy.

    Our use case: a multi-level hierarchy of paragraphs, some paragraphs containing other paragraphs.

    We added some custom presave entity hooks calling the new _entity_reference_revisions_delete_entity_orphans with the new $recursive_usage_check to be able to cleanup all the potential orphaned entities.

  • Pipeline finished with Success
    2 months ago
    Total: 159s
    #333601
  • Pipeline finished with Failed
    2 months ago
    Total: 146s
    #333603
  • Pipeline finished with Success
    2 months ago
    Total: 1141s
    #333607
  • Pipeline finished with Canceled
    2 months ago
    Total: 123s
    #333818
  • Pipeline finished with Canceled
    2 months ago
    Total: 79s
    #333819
  • Pipeline finished with Canceled
    2 months ago
    Total: 75s
    #333820
  • Pipeline finished with Canceled
    2 months ago
    Total: 490s
    #333821
  • Pipeline finished with Success
    2 months ago
    Total: 3113s
    #333822
  • 🇫🇷France mably

    Updated patch from MR to fix small typo in function name: refrence -> reference.

  • 🇨🇭Switzerland berdir Switzerland

    Instead of a a prefixed "internal" function, what if we already convert this to the new #Hook + #LegacyHook hook syntax? A single method can then implement both hooks on 11.1+ and the two old hooks can be marked as #LegacyHook. That's fully forward compatible and will not need to be touched anymore until D10 support is dropped.

    https://www.drupal.org/node/3442349

  • Pipeline finished with Success
    about 2 months ago
    Total: 160s
    #341435
  • 🇫🇷France mably

    Tried something with MR 62.

  • Pipeline finished with Success
    about 2 months ago
    Total: 238s
    #341442
  • 🇨🇭Switzerland berdir Switzerland

    Nice, reviewed.

  • Pipeline finished with Success
    about 2 months ago
    Total: 286s
    #341495
  • Pipeline finished with Success
    about 2 months ago
    Total: 314s
    #341500
  • 🇨🇭Switzerland berdir Switzerland

    Thanks for the quick turnaround. Tests would be nice, but I'm OK with merging this as it is now.

  • Pipeline finished with Skipped
    about 2 months ago
    #341508
    • berdir committed 160384c2 on 8.x-1.x authored by mably
      Issue #3388540 by mably, remco hoeneveld, berdir: Orphan Purger not...
  • 🇨🇭Switzerland berdir Switzerland
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇨🇭Switzerland berdir Switzerland

    Note: \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem::deleteRevision() already exists, so deleting a revision should in most cases directly delete that revision, so this will add considerably extra load on deleting revisions as it will expand the queue :-/

  • 🇨🇭Switzerland berdir Switzerland

    Reopening this for now, considering to revert this because this is a considerable overhead when doing everything twice. I'd like to understand the scenario when this is needed better. One option would be to remove revisionDelete().

  • 🇫🇷France mably

    Hi @berdir, what do you mean exactly by "doing everything twice"?

  • 🇨🇭Switzerland berdir Switzerland

    I mean that we'd immediately delete the revision but then also register a queue item to check whether or not we should delete that revision.

    So we need to figure out when and why deleteRevision() doesn't do its job, a test for that would be very helpful.

    The reason I commented and re-opened is that I noticed today on a client project that a node had 5000 revisions and node_revision_delete was somehow not running properly. So I did run the manual batch, and then, knowing about this issue, did run the manual ERR orphan purger. But it barely did anything and upon closer inspection I realized that basically all the revisions already had been deleted. So it was working as it should, for me anyway.

  • 🇫🇷France mably

    Our use case is to be able to properly delete a specific revision of a node, not the whole node, without having to run the orphan purger.

    The problem might be that be that we add several times the same entity to the orphan purger queue, possibly many times if we have a lot of revisions and we delete the node entirely.

    Could it be possible to store in a request cache the entities already added to the orphan purger queue so we don't add them several times?

  • Pipeline finished with Failed
    about 1 month ago
    Total: 151s
    #357323
  • 🇫🇷France mably

    Ok, I think I see what you mean when you say that everything is done twice.

    When running the orphan purger batch we don't need to add the processed entities to the purger queue.

    Is there a way to know that the hook are being called from the batch processing?

    If so, we could just skip the processing in such a situation.

    Anyway, I tried to work on a static cache to avoid processing multiple times the same entity in the same request, MR added to this issue.

Production build 0.71.5 2024