Lots of unnecessary querying for custom tokens

Created on 23 May 2016, almost 9 years ago
Updated 29 November 2023, over 1 year ago

Every time a token, of any type, is generated, token_custom tries to load it. In the vast majority of cases, this will be for a token type that there aren't any custom tokens for anyway, so this is rather unnecessary, and can be a performance problem.
Drupal's core path system uses a sort of cache/whitelist of which alias prefixes to cover, so it never bothers looking up aliases under other prefixes - this is a pattern that could be copied. See the attached patch.
A query is made for which token types have custom tokens defined. So then only tokens within those types are actually queried for.

On top of that, unfound tokens are repeatedly queried for if repeatedly generated. On querying for a token that does not have a match, the patch also adds that to the cache so that subsequent lookups don't need a DB hit.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom james.williams

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024