summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}