diff options
author | Dries Buytaert <dries@buytaert.net> | 2006-10-18 11:15:51 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2006-10-18 11:15:51 +0000 |
commit | d9ed1a9f664e58dc112192b6915362236a07bd3a (patch) | |
tree | 0d9eaad97201f279827207d1d3d979143568debe | |
parent | bf3e2f3ddf47d82c7b834f7d04f656b89f4ba442 (diff) | |
download | brdo-d9ed1a9f664e58dc112192b6915362236a07bd3a.tar.gz brdo-d9ed1a9f664e58dc112192b6915362236a07bd3a.tar.bz2 |
- Patch #87185 by robert: added caching to taxonomy_get_term().
-rw-r--r-- | modules/taxonomy/taxonomy.module | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index f48cab2af..e75b9f08c 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -899,6 +899,7 @@ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') { * @return * An array of all term objects in the tree. Each term object is extended * to have "depth" and "parents" attributes in addition to its normal ones. + * Results are statically cached. */ function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) { static $children, $parents, $terms; @@ -963,7 +964,18 @@ function taxonomy_get_synonym_root($synonym) { } /** - * Given a term id, count the number of published nodes in it. + * Count the number of published nodes classified by a term. + * + * @param $tid + * The term's ID + * + * @param $type + * The $node->type. If given, taxonomy_term_count_nodes only counts + * nodes of $type that are classified with the term $tid. + * + * @return int + * An integer representing a number of nodes. + * Results are statically cached. */ function taxonomy_term_count_nodes($tid, $type = 0) { static $count; @@ -988,7 +1000,16 @@ function taxonomy_term_count_nodes($tid, $type = 0) { } /** - * Helper for taxonomy_term_count_nodes(). + * Helper for taxonomy_term_count_nodes(). Used to find out + * which terms are children of a parent term. + * + * @param $tid + * The parent term's ID + * + * @return array + * An array of term IDs representing the children of $tid. + * Results are statically cached. + * */ function _taxonomy_term_children($tid) { static $children; @@ -1026,6 +1047,13 @@ function taxonomy_get_term_by_name($name) { /** * Return the vocabulary object matching a vocabulary ID. + * + * @param $vid + * The vocabulary's ID + * + * @return Object + * The vocabulary object with all of its metadata. + * Results are statically cached. */ function taxonomy_get_vocabulary($vid) { static $vocabularies = array(); @@ -1046,10 +1074,21 @@ function taxonomy_get_vocabulary($vid) { /** * Return the term object matching a term ID. + * + * @param $tid + * A term's ID + * + * @return Object + * A term object. Results are statically cached. */ function taxonomy_get_term($tid) { - // simple cache using a static var? - return db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)); + static $terms = array(); + + if (!isset($terms[$tid])) { + $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)); + } + + return $terms[$tid]; } function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { |