Problem/Motivation

As mentioned in #3484404: Drupal\Core\Datetime::dateFormat() does not properly cache results, there is a bug in core that is being triggered by SmartDateTrait. The result is tons of extra queries to the database looking for a non-existent date format, like this:

SELECT "cid", "data", "created", "expire", "serialized", "tags", "checksum" FROM "cache_config" WHERE "cid" IN ( 'core.date_format.' ) ORDER BY "cid"

Proposed resolution

The reason for this is the $type (second) parameter to \Drupal::service('date.formatter')->format(), as used in SmartDateTrait. For instance, this line:

$datetime = \Drupal::service('date.formatter')->format($times[$part], '', $format);

should be:

$datetime = \Drupal::service('date.formatter')->format($times[$part], 'custom', $format);

So, even if the parent issue does get fixed, this patch avoids even the first attempt to load the incorrect format.

CommentFileSizeAuthor
smart_date.2.diff1.91 KBgribnif

Comments

gribnif created an issue. See original summary.

mandclu’s picture

Status: Active » Needs review