Skip to content

Commit

Permalink
[backend] optimize Adrian's binary search
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Dec 14, 2012
1 parent 4c2fc53 commit 701ef12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/backend/BSXPathKeys.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,24 @@ sub boolop {
if ($v1->{'keys'} && !@{$v1->{'keys'}}) {
@k = ();
} elsif ($op == \&BSXPath::boolop_eq) {
@k = $db->keys($v1->{'path'}, $v2, $v1->{'keys'});
@k = grep {$k{$_}} @k if $v1->{'keys'};
#die("413 search limit reached\n") if $v1->{'limit'} && @k > $v1->{'limit'};
$negpol = 0;
if ($v1->{'keys'} && $v1->{'path'} && $db->{"fetch_$v1->{'path'}"}) {
# have super-fast select_path_from_key function
for my $k (@{$v1->{'keys'}}) {
my @d = $db->{"fetch_$v1->{'path'}"}->($db, $k);
next unless @d;
if (!$negpol) {
next unless grep {$_ eq $v2} @d;
} else {
next if grep {$_ eq $v2} @d;
}
push @k, $k;
}
} else {
@k = $db->keys($v1->{'path'}, $v2, $v1->{'keys'});
@k = grep {$k{$_}} @k if $v1->{'keys'};
#die("413 search limit reached\n") if $v1->{'limit'} && @k > $v1->{'limit'};
$negpol = 0;
}
} elsif ($op == \&BSXPath::boolop_not && $v1->{'keys'} && !exists($v1->{'value'})) {
for my $k (@{$v1->{'keys'}}) {
my $vv = $db->fetch($k);
Expand Down
10 changes: 10 additions & 0 deletions src/backend/bs_srcserver
Original file line number Diff line number Diff line change
Expand Up @@ -5826,6 +5826,15 @@ sub binary_key_to_data {
return $res;
}

sub binary_key_to_project {
my ($db, $key) = @_;
my @p = split('/', $key);
while (@p > 1 && $p[0] =~ /:$/) {
splice(@p, 0, 2, "$p[0]$p[1]");
}
return shift @p;
}

sub pattern_key_to_data {
my ($db, $key) = @_;
my @p = split('/', $key);
Expand Down Expand Up @@ -5876,6 +5885,7 @@ sub search_published_binary_id {
$binarydb->{'noindex'} = {'version' => 1, 'release' => 1, 'versrel' => 1, 'arch' => 1, 'project' => 1, 'repository' => 1, 'package' => 1, 'type' => 1, 'path/project' => 1, 'path/repository' => 1, 'baseproject' => 1};
$binarydb->{'indexfunc'} = {'project' => \&published_projectindexfunc };
$binarydb->{'fetch'} = \&binary_key_to_data;
$binarydb->{'fetch_project'} = \&binary_key_to_project;
$binarydb->{'cheapfetch'} = 1;
my $limit = defined($cgi->{'limit'}) ? $cgi->{'limit'} : 1000;
my $rootnode = BSXPathKeys::node($binarydb, '', $limit < 10 ? 1000 : $limit * 100);
Expand Down

0 comments on commit 701ef12

Please sign in to comment.