Created on 24 February 2024, 9 months ago
Updated 2 July 2024, 5 months ago

Problem/Motivation

Staring at xhprof output for lots of points, or large geometries, multiple calls were made to GeofieldItem::isEmpty() which is each time creating a geometry object to check if it's empty taking time/memory.

Looking at the code it doesn't need to do this. When the value is set of the field https://git.drupalcode.org/project/geofield/-/blob/8.x-1.x/src/Plugin/Fi... it already creates a geometry and checks if it is empty https://git.drupalcode.org/project/geofield/-/blob/8.x-1.x/src/Plugin/Fi... so the computed values in these columns are NULL if the \Geometry::isEmpty() is TRUE.

Proposed resolution

Don't recreate the Geometry and request if ::isEmpty, but check if one of the columns is NULL.

Remaining tasks

Make an MR.

API changes

None.

Although staring at this I also question if for a field item ::isEmpty https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21TypedData... it is actually correct to return if the geometry that is set is empty. It's a bit like a numeric field returning empty if it contains 0? The value is set, it has value, it is Geometry, it's just Empty Geometry https://trac.osgeo.org/postgis/wiki/DevWikiEmptyGeometry
However, altering that would be a BC break. So just re-using the previous Geometry isEmpty check seemed the better way.

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇳🇱Netherlands ekes

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

Merge Requests

  • !27isEmpty
    Merged

    🇳🇱Netherlands ekes
    updated 5 months ago

Comments & Activities

Production build 0.71.5 2024