This small change can reduce unnecessary function calls.

CommentFileSizeAuthor
flag-content_type_cache.patch586 bytesmaximpodorov

Comments

joachim’s picture

+++ b/plugins/content_types/flag_link/flag_link.inc
@@ -24,6 +24,11 @@ function flag_flag_link_content_type_info($entity_type) {
+  $types = &drupal_static(__FUNCTION__);
...
   $types = array();

Isn't the second assignment of $types going to clobber the static?

maximpodorov’s picture

It's a common pattern. You can find examples in common.inc in Drupal core.

joachim’s picture

Can you give me an example where the variable gets re-assigned like that?

maximpodorov’s picture

function drupal_get_destination() {
  $destination = &drupal_static(__FUNCTION__);

  if (isset($destination)) {
    return $destination;
  }

  if (isset($_GET['destination'])) {
    $destination = array('destination' => $_GET['destination']);
  }
  else {
    $path = $_GET['q'];
    $query = drupal_http_build_query(drupal_get_query_parameters());
    if ($query != '') {
      $path .= '?' . $query;
    }
    $destination = array('destination' => $path);
  }
  return $destination;
}
maximpodorov’s picture

Issue summary: View changes

This patch is the continuation of efforts expressed in
#2049087: Add static caching to ctools_token_content_type_content_types()
(the static caching code is included in the new ctools release).
It uses the same tactics, and reduces repeating of function calls (sometimes tens of thousand t() calls per page).
So, please, accept the patch.

joachim’s picture

Status: Needs review » Fixed

Sorry for the delay.

Committed. Thanks for the patch and the reminder!

git commit -m "Issue #2118483 by maximpodorov: Added static caching for CTools content type plugin." --author="maximpodorov "

maximpodorov’s picture

Than you. I hope this will help to improve the performance.

Status: Fixed » Closed (fixed)

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