summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Tags.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2016-07-03 11:56:07 +0200
committerYorhel <git@yorhel.nl>2016-07-03 11:56:09 +0200
commit5648ca9997e4d986799bccd877deaf72b47e48a0 (patch)
treebb7bd3ee1516688ffd3293ff0cc8394c0cbe8373 /lib/VNDB/DB/Tags.pm
parent92235222dba4e5d0c7713d53ef12e0f10e371b83 (diff)
DB::Tags::dbTTTree: Use hash lookup for parent IDs
Reduces page load time of the trait index from 200ms to 20ms. Also provides a slight improvement for other tag/trait tree views.
Diffstat (limited to 'lib/VNDB/DB/Tags.pm')
-rw-r--r--lib/VNDB/DB/Tags.pm7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index f3c901ab..10b45a4b 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -111,9 +111,10 @@ sub dbTTTree {
$id ? {'id = ?' => $id} : {"NOT EXISTS(SELECT 1 FROM ${type}s_parents WHERE $type = id)" => 1, 'state = 2' => 1},
!$back ? ('tp.parent = tt.id', "t.id = tp.$type") : ("tp.$type = tt.id", 't.id = tp.parent')
);
- for my $i (@$r) {
- $i->{'sub'} = [ grep $_->{parent} == $i->{id}, @$r ];
- }
+
+ my %pars; # parent-id -> [ child-object, .. ]
+ push @{$pars{$_->{parent}}}, $_ for(@$r);
+ $_->{'sub'} = $pars{$_->{id}} || [] for(@$r);
my @r = grep !delete($_->{parent}), @$r;
return $id ? $r[0]{'sub'} : \@r;
}