aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/MGA/Mirrors/DB.pm55
-rw-r--r--root/html/includes/mirrorslist.tt2
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 @@
<form action="[% c.uri_for() %]" METHOD="POST">
<select name="country">
<option value="">--</option>
-[% FOREACH country = c.model('Mirrors').country_list %]
+[% FOREACH country = c.model('Mirrors').country_list_with_mirror %]
<option value="[% country.code %]" [% "selected=select" IF country.code == c.req.param('country') %]>[% country.name | html %]</option>
[% END %]
</select>