/[drupal]/contributions/modules/advcache/DRUPAL-5-10/taxonomy_cache.patch
ViewVC logotype

Diff of /contributions/modules/advcache/DRUPAL-5-10/taxonomy_cache.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by firebus, Wed Sep 24 23:21:59 2008 UTC revision 1.2 by mikejoconnor, Thu Feb 26 13:39:12 2009 UTC
# Line 0  Line 1 
1    ? sites/all/modules
2    Index: modules/taxonomy/taxonomy.module
3    ===================================================================
4    RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
5    retrieving revision 1.330.2.17
6    diff -u -p -r1.330.2.17 taxonomy.module
7    --- modules/taxonomy/taxonomy.module    6 Jul 2008 00:50:44 -0000       1.330.2.17
8    +++ modules/taxonomy/taxonomy.module    18 Jul 2008 21:35:10 -0000
9    @@ -780,12 +780,25 @@ function taxonomy_node_get_terms($nid, $
10       static $terms;
11    
12       if (!isset($terms[$nid][$key])) {
13    -    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid);
14    -    $terms[$nid][$key] = array();
15    -    while ($term = db_fetch_object($result)) {
16    -      $terms[$nid][$key][$term->$key] = $term;
17    +    // This caching breaks taxonomy access! The results of db_rewrite_sql will
18    +    // be cached, meaning the first user to load this node after a cache
19    +    // refresh will set the permissions for everyone. If you are using a module
20    +    // that does query rewriting on taxonomy queries, don't use this patch.
21    +    // If you're not sure whether or not this is the case, don't use this patch!
22    +    $cache_key = 'node::'. $nid. '::'. $key;
23    +    if ($cache = cache_get($cache_key, 'cache_taxonomy')) {
24    +      $terms[$nid][$key] = unserialize($cache->data);
25    +    }
26    +    else {
27    +      $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid);
28    +      $terms[$nid][$key] = array();
29    +      while ($term = db_fetch_object($result)) {
30    +        $terms[$nid][$key][$term->$key] = $term;
31    +      }
32    +      cache_set($cache_key, 'cache_taxonomy', serialize($terms[$nid][$key]));
33         }
34       }
35    +
36       return $terms[$nid][$key];
37     }
38    
39    @@ -989,7 +1002,14 @@ function taxonomy_get_children($tid, $vi
40      */
41     function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) {
42       static $children, $parents, $terms;
43    -
44    +  if ((0 === $parent) && (-1 === $depth)) {
45    +    if ($cache = cache_get('tree::'. $vid, 'cache_taxonomy')) {
46    +      return unserialize($cache->data);
47    +    }
48    +    else {
49    +      $cache_tree = TRUE;
50    +    }
51    +  }
52       $depth++;
53    
54       // We cache trees, so it's not CPU-intensive to call get_tree() on a term
55    @@ -1023,6 +1043,10 @@ function taxonomy_get_tree($vid, $parent
56         }
57       }
58    
59    +  if ($cache_tree) {
60    +    cache_set('tree::'. $vid, 'cache_taxonomy', serialize($tree));
61    +  }
62    +
63       return $tree ? $tree : array();
64     }
65    
66    @@ -1146,13 +1170,19 @@ function taxonomy_get_vocabulary($vid) {
67       static $vocabularies = array();
68    
69       if (!array_key_exists($vid, $vocabularies)) {
70    -    $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid);
71    -    $node_types = array();
72    -    while ($voc = db_fetch_object($result)) {
73    -      $node_types[] = $voc->type;
74    -      unset($voc->type);
75    -      $voc->nodes = $node_types;
76    -      $vocabularies[$vid] = $voc;
77    +    if ($cache = cache_get('vocabulary::'. $vid, 'cache_taxonomy')) {
78    +      $vocabularies[$vid] = unserialize($cache->data);
79    +    }
80    +    else {
81    +      $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid);
82    +      $node_types = array();
83    +      while ($voc = db_fetch_object($result)) {
84    +        $node_types[] = $voc->type;
85    +        unset($voc->type);
86    +        $voc->nodes = $node_types;
87    +        $vocabularies[$vid] = $voc;
88    +        cache_set('vocabulary::'. $vid, 'cache_taxonomy', serialize($voc));
89    +      }
90         }
91       }
92    
93    @@ -1172,7 +1202,13 @@ function taxonomy_get_term($tid) {
94       static $terms = array();
95    
96       if (!isset($terms[$tid])) {
97    -    $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
98    +    if ($cache = cache_get('term::'. $tid, 'cache_taxonomy')) {
99    +      $terms[$tid] = unserialize($cache->data);
100    +    }
101    +    else {
102    +      $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
103    +      cache_set('term::'. $tid, 'cache_taxonomy', serialize($terms[$tid]));
104    +    }
105       }
106    
107       return $terms[$tid];
108    @@ -1301,8 +1337,8 @@ function taxonomy_render_nodes($result)
109     function taxonomy_nodeapi($node, $op, $arg = 0) {
110       switch ($op) {
111         case 'load':
112    -     $output['taxonomy'] = taxonomy_node_get_terms($node->nid);
113    -     return $output;
114    +      $output['taxonomy'] = taxonomy_node_get_terms($node->nid);
115    +      return $output;
116         case 'insert':
117           taxonomy_node_save($node->nid, $node->taxonomy);
118           break;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.3