Commit 3ecc390c authored by merlinofchaos's avatar merlinofchaos
Browse files

#102716: Reduced the number of JOINs for taxonomy hierarchy queries

parent fc3480b2
......@@ -127,5 +127,6 @@ Views --dev
o Capitalization and t() fixes to recent popular content and all time popular content views.
o #123986: documentation fix in argument handling code
o #111881: change 'user' table to use INNER join because every node has an author
o #102716: Reduced the number of JOINs for taxonomy hierarchy queries
......@@ -461,12 +461,12 @@ function _views_add_taxonomy($op, $value, $depth, &$query) {
$clause = "'" . implode("','", $value) . "'";
$where = "$tablename.tid IN ($clause)";
// for each depth > 0, add the next child in term_hierarchy to the join
// for each depth > 0, add the next parent in term_hierarchy to the join
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'tid'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_hierarchy', $thnum);
for ($i = 0; $i < $depth; $i++) {
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'tid'), 'right' => array('field' => 'tid')));
$thname = $query->get_table_name('term_hierarchy', $thnum);
$num = $query->add_table('term_data', false, 1, array('left' => array('table' => $thname, 'field' => 'parent'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_data', $num);
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'parent'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_hierarchy', $thnum);
$where .= " OR $tablename.tid IN ($clause)";
}
$query->add_where($where);
......@@ -487,12 +487,12 @@ function _views_add_taxonomy($op, $value, $depth, &$query) {
$tablename = $query->get_table_name('term_node', $num);
$where = "$tablename.tid = '$tid'";
// for each depth > 0, add the next child in term_hierarchy to the join
// for each depth > 0, add the next parent in term_hierarchy to the join
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'tid'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_hierarchy', $thnum);
for ($i = 0; $i < $depth; $i++) {
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'tid'), 'right' => array('field' => 'tid')));
$thname = $query->get_table_name('term_hierarchy', $thnum);
$num = $query->add_table('term_data', false, 1, array('left' => array('table' => $thname, 'field' => 'parent'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_data', $num);
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'parent'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_hierarchy', $thnum);
$where .= " OR $tablename.tid = '$tid'";
}
$query->add_where($where);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment