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