Huge performance issue due to bug

Davy Van Den Bremt - October 13, 2008 - 17:12
Project:Advanced User
Version:5.x-2.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

At the top of advuser.module there is a t() defined in a define(). This can not work and has huge performance issues.

define('ADVUSER_SUBSTITUTION_TEXT', t('<strong>Substitution variables</strong> available in subject and email body<br/><em> %user_name, %user_email, %user_status, %user_created, %user_theme, %user_timezone, %user_language, %user_signature, %site, %uri, %google_user (search google for user email), %yahoo_user (search yahoo for user email)</em>'));

In function locale() the global $locale isn't set yet when the define function runs. This way the locale cache is rebuilt on every page request (locale_refresh_cache). On a site with a lot of t() calls this means a huge cache_set (in our case 500kb).

function locale($string) {
  global $locale;
  static $locale_t;

  // Store database cached translations in a static var.
  if (!isset($locale_t)) {
    $cache = cache_get("locale:$locale", 'cache');

    if (!$cache) {
      locale_refresh_cache();
      $cache = cache_get("locale:$locale", 'cache');
    }
  }

The attached patch takes the t() away from the define() and puts a t() around each instance of the constant.

AttachmentSize
advuser.module.patch1.74 KB

#1

earnie - November 24, 2008 - 12:56

Does this affect Drupal 5?

#2

Davy Van Den Bremt - November 24, 2008 - 18:50

Yes, this was tested in Drupal 5.

#3

earnie - January 13, 2009 - 13:46
Version:HEAD» 5.x-2.x-dev

#4

earnie - January 13, 2009 - 13:55
Status:needs review» fixed

Committed patch to HEAD, 5.x-2.x-dev and 6.x-2.x-dev

#5

System Message - January 27, 2009 - 14:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.