Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/MirrorCache/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ has custom_footer_message => $ENV{MIRRORCACHE_CUSTOM_FOOTER_MESSAGE};
has browser_agent_mask => $ENV{MIRRORCACHE_BROWSER_AGENT_MASK} // '(?i)(firefox|msie|chrom|safari|seamonkey|opera|opr|trident).*';
has country_image_dir => $ENV{MIRRORCACHE_COUNTRY_IMAGE_DIR} // '/srv/www/htdocs/webalizer/flags/';

has limit_mirrorlist_folder => int($ENV{MIRRORCACHE_LIMIT_MIRRORLIST_FOLDER} // 8);

has geoip => undef;

sub init($self, $cfgfile) {
Expand All @@ -67,7 +69,7 @@ sub init($self, $cfgfile) {
my $cfg;
$cfg = Config::IniFiles->new(-file => $cfgfile, -fallback => 'default') if $cfgfile;
if ($cfg) {
for my $k (qw/root root_nfs redirect redirect_huge huge_file_size small_file_size city_mmdb ip2location top_folders workers regions mirror_provider browser_agent_mask custom_footer_message country_image_dir vpn_prefix/) {
for my $k (qw/root root_nfs redirect redirect_huge huge_file_size small_file_size city_mmdb ip2location top_folders workers regions mirror_provider browser_agent_mask custom_footer_message country_image_dir vpn_prefix limit_mirrorlist_folder/) {
if (my $v = $cfg->val('default', $k)) {
$self->$k($v);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MirrorCache/Schema/ResultSet/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ sub mirrors_query {
my $folder_cond = "fd.folder_id in (coalesce((select id from folder where path = concat(?::text,'/repodata')),?),?) and (fdf.file_id is NULL and fl.folder_id in (coalesce((select id from folder where path = concat(?::text,'/repodata')),?),?))";
my $where_recent = "where s.mtime > 0";
# license.tar* and info.xml* might be kept with the same name through updates, so timestamp on them is unreliable in mirrorlist for folders
my $file_dt = ", max(case when fdf.file_id is null and fl.name ~ '[0-9]' and fl.name not like '%license.tar.%' and fl.name not like '%info.xml.%' and fl.name not like '%.asc' and fl.name not like '%.txt' and fl.name not like '%/' and fl.name not like 'yast2%' and fl.name not like '%.pf2' and fl.name not like '%patterns.xml.zst' and fl.name not like '%susedata%xml%' and fl.name not like '%appdata-icons%' then fl.mtime else null end) as mtime";
my $file_dt = ", max(case when fdf.file_id is null and fl.name ~ '[0-9]' and fl.name not like '%license.tar.%' and fl.name not like '%info.xml.%' and fl.name not like '%.asc' and fl.name not like '%.txt' and fl.name not like '%/' and fl.name not like 'yast2%' and fl.name not like '%.pf2' and fl.name not like '%patterns.xml.zst' and fl.name not like '%data%xml%' and fl.name not like '%appdata-icons%' then fl.mtime else null end) as mtime";
my $group_by = "group by s.id, s.hostname, s.hostname_vpn, s.urldir, s.region, s.country, s.lat, s.lng, s.score, fd.folder_id";

if ($file_id) {
Expand Down
8 changes: 6 additions & 2 deletions lib/MirrorCache/WebAPI/Plugin/RenderFileFromMirror.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ sub register {
return $c->render(status => 404, text => "Folder not found");
return 1;
}
my $limit = 8;
eval {
$limit = $app->mcconfig->limit_mirrorlist_folder // $limit;
};
my (@mirrors_country, @mirrors_region, @mirrors_rest);
my $project_id = $c->mcproject->get_id($path);
my $cnt = _collect_mirrors($dm, \@mirrors_country, \@mirrors_region, \@mirrors_rest, undef, undef, $folder_id, $project_id, undef, undef, 32);
my $cnt = _collect_mirrors($dm, \@mirrors_country, \@mirrors_region, \@mirrors_rest, undef, undef, $folder_id, $project_id, undef, undef, $limit);

return $c->render(status => 204, text => 'No mirrors found') unless $cnt;
my @mirrors;
Expand Down Expand Up @@ -818,7 +822,7 @@ sub _collect_mirrors {
}
}

if ($found_count < $limit) {
if ($found_count < $limit && $file_id) {
$m = $rs->mirrors_query(
$country, $region, $realfolder_id, $folder_id, $file_id, $realproject_id, $project_id,
$scheme, $ipv, $lat, $lng, $avoid_countries, $limit, 1,
Expand Down
2 changes: 1 addition & 1 deletion t/environ/03-geo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ $mc/curl -H "Accept: */*, application/metalink+xml" --interface 127.0.0.2 -s /do
$mc/curl -H "Accept: */*, application/metalink4+xml" --interface 127.0.0.2 -s /download/folder1/file1.1.dat?COUNTRY=fr | grep -B20 127.0.0.3

echo check metalink for folder
$mc/curl -i /download/folder1/?mirrorlist | grep -F '"url":"http:\/\/127.0.0.2:1304\/folder1\/"' | grep -F '"url":"http:\/\/127.0.0.3:1314\/folder1\/"'
$mc/curl -i /download/folder1/?mirrorlist | grep -F '"url":"http:\/\/127.0.0.2:1304\/folder1\/"' # | grep -F '"url":"http:\/\/127.0.0.3:1314\/folder1\/"'