Problem/Motivation

Smart Date calls DateFormatter::format() with an empty string as $type and passes the pattern via $format. On Drupal core before 11.4, any $type other than 'custom' triggers DateFormatter::dateFormat(), which tries to load a
date_format config entity with the ID ''. In views rendering many Smart Date values this adds a noticeable number of unnecessary calls (see screenshots, before and after).

Core 11.4 skips the lookup for an empty type (#3520188: Do not try to load date format when custom date format is provided but not declared), but Smart Date still supports Drupal 10 and earlier 11.x releases, where the overhead remains. Passing 'custom' is also the documented way to use a custom pattern.

Steps to reproduce

  1. Drupal 10 or 11 before 11.4, create a view listing many entities with a Smart Date field using the Smart Date formatter.
  2. Profile the page (e.g. XHProf/Blackfire): DateFormatter::dateFormat() is called for every formatted value.

Proposed resolution

Pass 'custom' as the format type in all calls that provide an explicit pattern:

  • SmartDateTrait
  • SmartDatePluginTrait
  • SmartDateTokensHooks

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork smart_date-3519986

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

tobiasb created an issue. See original summary.

tobiasb’s picture

StatusFileSize
new208.5 KB
tobiasb’s picture

Title: Set missing datetime type » Set missing date format type

tobiasb’s picture

Assigned: tobiasb » Unassigned
Status: Active » Needs review
tobiasb’s picture

Version: 4.2.x-dev » 4.3.x-dev
Assigned: Unassigned » tobiasb
Status: Needs review » Needs work
tobiasb’s picture

Assigned: tobiasb » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
tobiasb’s picture

Issue summary: View changes