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