From f438c3aee114497ce57cc3569589e690dbe1a0c3 Mon Sep 17 00:00:00 2001 From: Olivier Thauvin Date: Mon, 4 Oct 2010 09:48:15 +0000 Subject: - limit countries list to one having mirrors --- lib/MGA/Mirrors/DB.pm | 55 +++++++++++++++++++++++++++++++++++++-- root/html/includes/mirrorslist.tt | 2 +- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/MGA/Mirrors/DB.pm b/lib/MGA/Mirrors/DB.pm index 4e71e5b..1c79d8b 100644 --- a/lib/MGA/Mirrors/DB.pm +++ b/lib/MGA/Mirrors/DB.pm @@ -115,6 +115,18 @@ sub country_info { $res } +sub country_list_with_mirror { + my ($self) = @_; + my $list = $self->db->prepare(q{ + select * from countries where code in (select country from hosts + join toplevel_urls on toplevel_urls.hostname = hosts.hostname) + order by name + }); + $list->execute; + return $list->fetchall_arrayref({}); +} + + sub country_list { my ($self) = @_; my $list = $self->db->prepare(q{ @@ -145,6 +157,41 @@ sub arch_list { return $list->fetchall_hashref([qw(arch)]); } +sub mirror_level { + my ($self, $hostname) = @_; + my $minfo = $self->find_mirrors({ + hostname => $hostname + }); + if (my $mir = @{ $minfo || []}[0]) { + if ($mir->{syncfrom}) { + return $self->_mirror_level($hostname); + } else { + return + } + } else { + return; + } +} + +sub _mirror_level { + my ($self, $hostname, @prev) = @_; + return if (grep { $hostname eq $_ } @prev); + my $minfo = $self->find_mirrors({ + hostname => $hostname + }); + if (my $mir = @{ $minfo || []}[0]) { + if ($mir->{syncfrom}) { + my $res = $self->_mirror_level($mir->{syncfrom}, $hostname, @prev); + return defined($res) ? $res + 1 : undef; + } else { + return 0; + } + } else { + return 0; + } +} + + sub mirror_validity { my ($self, $uri) = @_; my $listf = $self->db->prepare(q{ @@ -252,7 +299,7 @@ sub find_mirrors { coalesce(hosts.latitude, countries.latitude) as latitude, coalesce(hosts.longitude, countries.longitude) as longitude from hosts - left join countries on countries.code = hosts.country + join countries on countries.code = hosts.country where hosts.hostname in (select hostname from toplevel_urls %s) %s }; @@ -327,10 +374,14 @@ sub _find_distributions { my ($self, $filters, $key) = @_; my $query = q{ - select *, toplevel_urls.path || distributions.relpath as path from hosts + select *, toplevel_urls.path || distributions.relpath as path, + coalesce(hosts.latitude, countries.latitude) as latitude, + coalesce(hosts.longitude, countries.longitude) as longitude + from hosts join toplevel_urls on toplevel_urls.hostname = hosts.hostname join distributions_validity on toplevel_urls.key = distributions_validity.urlskey join distributions on distributions.dkey = distributions_validity.distributionkey + join countries on countries.code = hosts.country }; my @vals; diff --git a/root/html/includes/mirrorslist.tt b/root/html/includes/mirrorslist.tt index d10d5de..3332a54 100644 --- a/root/html/includes/mirrorslist.tt +++ b/root/html/includes/mirrorslist.tt @@ -1,7 +1,7 @@
-- cgit v1.2.1