follow-up to: #254491: Standardize static caching

see last patch examples: http://drupal.org/node/254491#comment-1430180 and also: http://drupal.org/node/224333#static_variable_api

Apply this conversion pattern to includes/database to convert all static variables there. Pay close attention to any place a reset parameter is provided and add a call to drupal_static_reset() where appropriate (e.g. in any calling function that uses the reset parameter)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

Per discussion w/ catch - if you have a variable name more complex than just __FUNCTION__, use a ':' to separate the suffix (this will avoid colliding with any other valid function name). e.g. :

&drupal_static(__FUNCTION__ . ':second_var');
JamesAn’s picture

Status: Active » Needs review
FileSize
5.21 KB

All the static variables I encountered here didn't seem to ever need resetting.

There were a couple adjustments I made:

  • I removed a couple of the conditional statements (in pager_get_querystring and theme_pager_link) as they simply initialize the static vars.
  • The static vars that weren't converted were documented
  • I made a variable in the pgSQL and SQLite drivers static, mirroring the MySQL driver.

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

@#2
You can't use function calls when defining static variables, that's why these additional if's are needed.

JamesAn’s picture

Status: Needs work » Needs review
FileSize
5.15 KB

Oops. I missed that PHP detail.. ^^" That explains why the patch didn't work. Yey me and my self-taught PHP knowledge. XD

pwolanin’s picture

I might also convert function pager_get_querystring() - for example if a test is executing several different paths during one page load.

Dries’s picture

Status: Needs review » Needs work

theme_pager_link() contains some changes that seem irrelevant to this patch, and that are not documented.

Otherwise this looks fine.

JamesAn’s picture

Status: Needs work » Needs review
FileSize
4.59 KB

Thanks for catching those bits. I've converted pager_get_querystring() and fixed the problem with theme_pager_link().

Status: Needs review » Needs work

The last submitted patch failed testing.

JamesAn’s picture

Status: Needs work » Needs review
FileSize
4.59 KB

Oy vey.. there was a dangling parenthesis.

JamesAn’s picture

FileSize
4.47 KB

I broke up $string = &drupal_static(__FUNCTION__, drupal_query_string_encode($_REQUEST, array_merge(array('q', 'page'), array_keys($_COOKIE)))); so that drupal_query_string_encode() is only run when $string is NULL.

Here it is.

JamesAn’s picture

FileSize
3.55 KB

Oops! I mistakenly included pager.inc into this issue. Changes to that file belong to #422370: Revisit and convert mail.inc, module.inc, pager.inc to use static caching API. This patch reflects this fix and no longer includes pager.inc changes.

The patch of the other issue reflects this realization too.

Dries’s picture

Status: Needs review » Fixed

Thanks JamesAn. Committed to CVS HEAD.

Status: Fixed » Closed (fixed)

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