Skip to content

Commit

Permalink
Optimization: assume package managers never want to render dir
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Sep 21, 2022
1 parent 9240d09 commit 1a02f30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/MirrorCache/Datamodule.pm
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ sub redirect($self, $url) {
}

sub _init_headers($self) {
$self->_agent('');
my $headers = $self->c->req->headers;
return unless $headers;
$self->_agent($headers->user_agent ? $headers->user_agent : '');
Expand Down
10 changes: 9 additions & 1 deletion lib/MirrorCache/WebAPI/Plugin/Dir.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ sub register {
return $app;
}

# Assume UserAgent of such pattern never lists directories and only needs to render files
my $PACKAGE_MANAGER_PATTERN = 'ZYpp .*|Debian APT.*|libdnf.*|osc.*';

sub indx {
my $c = shift;
my $reqpath = $c->req->url->path;
Expand Down Expand Up @@ -75,6 +78,11 @@ sub indx {
|| _render_from_db($dm)
|| _local_render($dm, 1); # check if we should render local when metalink cannot be provided

if ($dm->agent =~ qr/$PACKAGE_MANAGER_PATTERN/) {
my ($path, $trailing_slash) = $dm->path;
return $root->render_file($dm, $path . $trailing_slash);
}

my $tx = $c->render_later->tx;
my $rendered;
my $handle_error = sub {
Expand Down Expand Up @@ -366,7 +374,7 @@ sub _guess_what_to_render {
# this should happen only if $url is a valid file or non-existing path
return $root->render_file($dm, $path . $trailing_slash);
})->catch(sub {
my $res = $root->render_file($dm, $path . $trailing_slash);
$root->render_file($dm, $path . $trailing_slash);
my $msg = "Error while guessing how to render $url: ";
if (1 == scalar(@_)) {
$msg = $msg . $_[0];
Expand Down

0 comments on commit 1a02f30

Please sign in to comment.