- Patch #142051 by catch, moonray: static cache for taxonomy_get_parents() and taxonomy_get_children().
parent
c92ddd4cb8
commit
4b8ba4fa2c
|
@ -563,6 +563,8 @@ function taxonomy_term_delete($tid) {
|
||||||
function taxonomy_terms_static_reset() {
|
function taxonomy_terms_static_reset() {
|
||||||
drupal_static_reset('taxonomy_term_count_nodes');
|
drupal_static_reset('taxonomy_term_count_nodes');
|
||||||
drupal_static_reset('taxonomy_get_tree');
|
drupal_static_reset('taxonomy_get_tree');
|
||||||
|
drupal_static_reset('taxonomy_get_parents');
|
||||||
|
drupal_static_reset('taxonomy_get_children');
|
||||||
entity_get_controller('taxonomy_term')->resetCache();
|
entity_get_controller('taxonomy_term')->resetCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,6 +612,11 @@ function taxonomy_vocabulary_get_names() {
|
||||||
*/
|
*/
|
||||||
function taxonomy_get_parents($tid, $key = 'tid') {
|
function taxonomy_get_parents($tid, $key = 'tid') {
|
||||||
if ($tid) {
|
if ($tid) {
|
||||||
|
$tids = &drupal_static(__FUNCTION__, array());
|
||||||
|
if (isset($tids[$key][$tid])) {
|
||||||
|
$parents = $tids[$key][$tid];
|
||||||
|
}
|
||||||
|
else {
|
||||||
$query = db_select('taxonomy_term_data', 't');
|
$query = db_select('taxonomy_term_data', 't');
|
||||||
$query->join('taxonomy_term_hierarchy', 'h', 'h.parent = t.tid');
|
$query->join('taxonomy_term_hierarchy', 'h', 'h.parent = t.tid');
|
||||||
$result = $query
|
$result = $query
|
||||||
|
@ -624,6 +631,7 @@ function taxonomy_get_parents($tid, $key = 'tid') {
|
||||||
foreach ($result as $parent) {
|
foreach ($result as $parent) {
|
||||||
$parents[$parent->$key] = $parent;
|
$parents[$parent->$key] = $parent;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $parents;
|
return $parents;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -660,6 +668,11 @@ function taxonomy_get_parents_all($tid) {
|
||||||
* Find all children of a term ID.
|
* Find all children of a term ID.
|
||||||
*/
|
*/
|
||||||
function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
|
function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
|
||||||
|
$tids = &drupal_static(__FUNCTION__, array());
|
||||||
|
if (isset($tids[$vid][$tid])) {
|
||||||
|
$children = $tids[$vid][$tid];
|
||||||
|
}
|
||||||
|
else {
|
||||||
$query = db_select('taxonomy_term_data', 't');
|
$query = db_select('taxonomy_term_data', 't');
|
||||||
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
|
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
|
||||||
$query
|
$query
|
||||||
|
@ -678,6 +691,8 @@ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
|
||||||
foreach ($result as $term) {
|
foreach ($result as $term) {
|
||||||
$children[$term->$key] = $term;
|
$children[$term->$key] = $term;
|
||||||
}
|
}
|
||||||
|
$tids[$vid][$tid] = $children;
|
||||||
|
}
|
||||||
return $children;
|
return $children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue