Problem/Motivation

In #2498919: Node::isPublished() and Node::getOwnerId() are expensive, it was identified that Node::isPublished is slow, so a cache was introduced through getEntityKey. The issue introduced the following change to isPublished:

+++ b/core/modules/node/src/Entity/Node.php
@@ -258,7 +267,7 @@ public function setSticky($sticky) {
-    return (bool) $this->get('status')->value;
+    return (bool) $this->getEntityKey('status');

and our current implementation is:

  public function isPublished() {
    $key = $this->getEntityType()->getKey('published');
    return (bool) $this->get($key)->value;
  }

Proposed resolution

Make use of getEntityKey in EntityPublishedTrait

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Sam152 created an issue. See original summary.

sam152’s picture

Status: Active » Needs review
StatusFileSize
new604 bytes

Seeing if anything breaks with this change. This is possibly impacted by a bug being fixed in #2961986: The ContentEntityBase entity key cache is purged incorrectly when two keys exist for one field..

Status: Needs review » Needs work

The last submitted patch, 2: 2962304-2.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 2: 2962304-2.patch, failed testing. View results

sam152’s picture

Title: EntityPublishedTrait should use getEntityKey for better performance » [PP-1] EntityPublishedTrait should use getEntityKey for better performance
Status: Needs work » Needs review
Related issues: +#2961986: The ContentEntityBase entity key cache is purged incorrectly when two keys exist for one field.
StatusFileSize
new7.65 KB

Applying this with the blocker seems to fix a few tests. Testing with the blocker applied.

Edit: Yep! The blocker was the only thing preventing us from using this in EntityPublishedTrait.

tstoeckler’s picture

Status: Needs review » Postponed

Looks great, thanks! Can be RTBC once the other is in.

sam152’s picture

Status: Postponed » Needs review
StatusFileSize
new604 bytes

Blocker is in.

amietpatial’s picture

StatusFileSize
new161.82 KB

@Sam152 I applied your patch and it works fine

tstoeckler’s picture

Title: [PP-1] EntityPublishedTrait should use getEntityKey for better performance » EntityPublishedTrait should use getEntityKey for better performance
Status: Needs review » Reviewed & tested by the community

Perfect, thank you!

alexpott’s picture

@amietpatial thanks for testing the patch but images of patches being applied don't tell us anything that the testbot does not already tell us.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 52fdfaa and pushed to 8.6.x. Thanks!

  • alexpott committed 52fdfaa on 8.6.x
    Issue #2962304 by Sam152: EntityPublishedTrait should use getEntityKey...

Status: Fixed » Closed (fixed)

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