From d748d69351f92825657776c24a5b7e8460120960 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 7 Sep 2004 15:34:36 +0000 Subject: [PATCH] speed improvement in page tree --- docs/changelog/6.x.x.txt | 3 ++- lib/DBIx/Tree/NestedSet.pm | 22 ++++------------------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index b21f4a4fa..e3bb9d6d1 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -1,5 +1,6 @@ 6.2.2 - + - Made a dramatic performance enhancement to the page tree system by + restructuring an overused, and inefficent method. 6.2.1 diff --git a/lib/DBIx/Tree/NestedSet.pm b/lib/DBIx/Tree/NestedSet.pm index 271a0ab56..49458f6f0 100644 --- a/lib/DBIx/Tree/NestedSet.pm +++ b/lib/DBIx/Tree/NestedSet.pm @@ -573,27 +573,13 @@ sub get_self_and_children_flat{ # If they have changed the id name but still pass in the ID value in the id parameter, fix it. $params{$id_name}=$params{id} } - my $id_SQL; + my $id_SQL; if (defined $params{$id_name}) { - my ($left_value,$right_value)=$dbh->selectrow_array("select $left,$right from $table where $id_name=?",undef,($params{$id_name})); - $id_SQL="and (n1.$left between " . $dbh->quote($left_value)." and ".$dbh->quote($right_value).") "; + my ($left_value,$right_value,$depth_value)=$dbh->selectrow_array("select $left,$right,depth from $table where $id_name=?",undef,($params{$id_name})); + $id_SQL="where $left between " . $dbh->quote($left_value)." and ".$dbh->quote($right_value)." having level <=".($params{depth} + $depth_value+2); } - my $tree_structure=$dbh->selectall_arrayref("select count(n2.${id_name}) as level,n1.* from $table as n1, $table as n2 where (n1.$left between n2.$left and n2.$right) $id_SQL group by n1.${id_name} order by n1.$left",{Columns=>{}}); - my $start_level=$tree_structure->[0]->{level}; - if (defined $params{depth} && $tree_structure) { - #We wanna chop down the tree. - my @temp_tree; - if (defined $params{depth}) { - foreach my $node (@$tree_structure) { - if ($node->{level} <= ($params{depth} + $start_level)) { - push @temp_tree,$node; - } - } - } - return \@temp_tree; - } else { + my $tree_structure=$dbh->selectall_arrayref("select depth+2 as level,$table.* from $table $id_SQL order by $left",{Columns=>{}}); return $tree_structure; - } } ########################################