Problem/Motivation

In \Drupal\focal_point\FocalPointManager::getCropEntity(), we use \Drupal\crop\Entity\Crop::cropExists() before calling \Drupal\crop\Entity\Crop::findCrop() or creating a new Crop entity.
This can cause a point of failure when cropExists returns TRUE and findCrop returns NULL (this can happen during migrations or content deployment for example) and it adds an unneeded database request.

FYI, the type of error triggered in this case is:
Error: Call to a member function isNew() on null in /app/web/modules/contrib/focal_point/focal_point.module on line 79 #0 /app/web/modules/contrib/focal_point/focal_point.module(53): focal_point_entity_update(Object(Drupal\media\Entity\Media))

Proposed resolution

Only use the \Drupal\crop\Entity\Crop::findCrop() method and test its result.

CommentFileSizeAuthor
#5 3513777-5.patch744 bytesduaelfr
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

duaelfr created an issue. See original summary.

duaelfr changed the visibility of the branch 3513777-simplify-getcropentity to hidden.

duaelfr’s picture

Status: Active » Needs review
duaelfr’s picture

Issue summary: View changes
StatusFileSize
new744 bytes

Here is a patch for composer

catch’s picture

Priority: Minor » Normal
Status: Needs review » Reviewed & tested by the community

Just found this profiling a site, the MR is exactly what I came up with.

I'm seeing this take 40ms compared to 20ms for actually loading the crop entity, maybe due to the entity query that runs, so bumping priority.

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

rajeshreeputra’s picture

Status: Reviewed & tested by the community » Fixed

Added to merge train!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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