aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA
diff options
context:
space:
mode:
authorOlivier Thauvin <nanardon@mageia.org>2010-10-04 09:48:15 +0000
committerOlivier Thauvin <nanardon@mageia.org>2010-10-04 09:48:15 +0000
commitf438c3aee114497ce57cc3569589e690dbe1a0c3 (patch)
treeed5bff02a5b085db74816d198bea09f1cc337ecf /lib/MGA
parente52246e2ad626b360613ec05401dc3c91c5cec3f (diff)
downloadmgamirrors-f438c3aee114497ce57cc3569589e690dbe1a0c3.tar
mgamirrors-f438c3aee114497ce57cc3569589e690dbe1a0c3.tar.gz
mgamirrors-f438c3aee114497ce57cc3569589e690dbe1a0c3.tar.bz2
mgamirrors-f438c3aee114497ce57cc3569589e690dbe1a0c3.tar.xz
mgamirrors-f438c3aee114497ce57cc3569589e690dbe1a0c3.zip
- limit countries list to one having mirrors
Diffstat (limited to 'lib/MGA')
-rw-r--r--lib/MGA/Mirrors/DB.pm55
1 files changed, 53 insertions, 2 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;