The function pathauto_punctuation_chars() initializes an array with among other 32 translated descriptions. This function gets called in a number of situations of which only 2 of them actually use the descriptions. To prevent calls to t() (that lead to a database call) in the other situations it is better to move the call to t() from this function to their actual use.

actual use when called via
pathauto_settings_form() or
pathauto_settings_form_validate()

not used when called via:
pathauto_form_alter() or
pathauto_node_update_alias() or
pathauto_taxonomy_term_update_alias() or
pathauto_user_update_alias() or
pathauto_blog_update_alias()

This will lead to a (small) performance improvement on almost all node/term/user insert, edit, update actions.

CommentFileSizeAuthor
#4 1043424.patch9.02 KBfietserwin
#1 no_translate.patch7.31 KBfietserwin

Comments

fietserwin’s picture

StatusFileSize
new7.31 KB
fietserwin’s picture

Patch is against the 2011-01-13 7.x-1.0-beta1 version.

dave reid’s picture

Status: Active » Closed (duplicate)

That won't fly with translators. You cannot use t() with a variable as localize.drupal.org won't know what strings there are to translate. The better solution is to statically cache the punctuation replacement so it's only run through once per request. We're already working on this at #834198: Improve performance of pathauto_cleanstring() and pathauto_get_placeholders(), so I'm marking this issue as a duplicate.

fietserwin’s picture

Status: Closed (duplicate) » Needs review
StatusFileSize
new9.02 KB

But I was talking about even preventing the "once per request" in the given cases (as pathauto_punctuation_chars() already uses a static variable to prevent "more than once per request"). Thus not a duplicate. But given that the texts are unfindable for localize.drupal.org I can agree that this is not the way to go.
So just one more (the last) try...

dave reid’s picture

Status: Needs review » Closed (duplicate)

I don't agree about splitting this up into two new functions. We don't know who may be calling this and using its data. This should be taken care of for good with #1189508: Allow pathauto_punctuation_chars() to be altered and cached since we will store the results of this in the cache and any further calls even across requests will not call t().

fietserwin’s picture

Looks good, thanks.