I'm working on making the community-managed taxonomy module so I'm looking at taxonomy.module more closely than is probably healthy for either of us...
This is either a request for an explanation of a finer point of SQL that I don't understand, or a suggestion that 25 characters, namely "ORDER BY v.weight, v.name", can be struck from taxonomy.module. I'll make a patch if the latter.
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);
But v.vid is a primary key so all v (vocabulary) components are the same for each row of the result set. In fact, this is relied on later in the code where the entire object is repeatedly created ( while ($voc = db_fetch_object($result)) with only the (vocabulary node) type aggregated and added on each time, until done.
So is there any purpose to the two-part ORDER BY clause?
... now that I've expended the most discussion for least importance in the history of Drupal...
The whole function, for reference:
/**
* 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();
if (!array_key_exists($vid, $vocabularies)) {
$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);
$node_types = array();
while ($voc = db_fetch_object($result)) {
$node_types[] = $voc->type;
unset($voc->type);
$voc->nodes = $node_types;
$vocabularies[$vid] = $voc;
}
}
return $vocabularies[$vid];
}| Comment | File | Size | Author |
|---|---|---|---|
| #3 | taxonomy_vocabulary_load.patch.patch | 935 bytes | wim leers |
Comments
Comment #1
wim leersWe're selecting only one vocabulary, so I think you're right. A vid is unique, so only one result can be found, no need to order it by v.weight or v.name then.
Comment #2
wim leersComment #3
wim leersPatch attached.
Comment #4
wim leersBetter title.
Comment #5
dmitrig01 commentedRTBC
Comment #6
gerhard killesreiter commentedack, the order by doesn't make any sense in this case.
Comment #7
dries commentedCommitted! Thanks a bundle. Good catch too. :)
Comment #8
(not verified) commented