From 4856e27936b1403dab3252322229bad0f63a41cf Mon Sep 17 00:00:00 2001
From: Silvio <silvio@socioambiental.org>
Date: Tue, 19 Nov 2013 16:01:21 -0200
Subject: Implementing static cache at jquery_drawer_page()

---
 jquery_drawer.module | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/jquery_drawer.module b/jquery_drawer.module
index 682e506..5f759d3 100644
--- a/jquery_drawer.module
+++ b/jquery_drawer.module
@@ -185,31 +185,36 @@ function jquery_drawer_get_children($tid = NULL) {
  * Menu callback.
  */
 function jquery_drawer_page($tid = NULL) {
-  $output  = '';
-  $nodes   = taxonomy_select_nodes(array($tid));
-  $base    = variable_get('jquery_drawer_link', 'node');
-  $tree    = jquery_drawer_get_children($tid);
-  $output .= '<ul id="drw_item" class="hidden">';
-
-  // First render all nodes whose parent is $term
-  while ($node = db_fetch_object($nodes)) {
-    path_nodeapi($node,'load','');
-    $link['title']  = $node->title;
-    $link['href']   = ($node->path?$node->path:"$base/". $node->nid);
-    $output        .= theme('jquery_drawer_link', $link);
-  }
+  static $cache = array();
 
-  // Add other nodes
-  if (is_array($tree) && !empty($tree)) {
-    foreach ($tree as $term) {
-      $output .= taxonomy_node_tree_list($term, 'jquery_drawer', 'hidden', $base);
+  if (!isset($cache[$tid])) {
+    $output  = '';
+    $nodes   = taxonomy_select_nodes(array($tid));
+    $base    = variable_get('jquery_drawer_link', 'node');
+    $tree    = jquery_drawer_get_children($tid);
+    $output .= '<ul id="drw_item" class="hidden">';
+
+    // First render all nodes whose parent is $term
+    while ($node = db_fetch_object($nodes)) {
+      path_nodeapi($node,'load','');
+      $link['title']  = $node->title;
+      $link['href']   = ($node->path?$node->path:"$base/". $node->nid);
+      $output        .= theme('jquery_drawer_link', $link);
     }
-  }
-  else {
-    $output .= t('No content exists for this topic yet.');
-  }
 
-  $output .= '</ul></li>';
+    // Add other nodes
+    if (is_array($tree) && !empty($tree)) {
+      foreach ($tree as $term) {
+        $output .= taxonomy_node_tree_list($term, 'jquery_drawer', 'hidden', $base);
+      }
+    }
+    else {
+      $output .= t('No content exists for this topic yet.');
+    }
+
+    $output      .= '</ul></li>';
+    $cache[$tid]  = $output;
+  }
 
   // Display output
   echo($output);
-- 
cgit v1.2.3