Remove scored based mirrorlist sorting

Users may use the returned mirror list as-is without sorting it
themselves. This may lead to the first mirror in the list being
overloaded. Prevent this by not returning a sorted list.

References: https://lists.archlinux.org/pipermail/arch-dev-public/2017-January/028681.html

Signed-off-by: Florian Pritz <bluewind@xinu.at>
This commit is contained in:
Florian Pritz 2017-02-15 19:55:53 +01:00 committed by Angel Velasquez
parent 210eb68a41
commit 644864de28
3 changed files with 6 additions and 5 deletions

View File

@ -10,6 +10,7 @@
from ..models import MirrorUrl, MirrorProtocol from ..models import MirrorUrl, MirrorProtocol
from ..utils import get_mirror_statuses from ..utils import get_mirror_statuses
import random
class MirrorlistForm(forms.Form): class MirrorlistForm(forms.Form):
country = forms.MultipleChoiceField(required=False, country = forms.MultipleChoiceField(required=False,
@ -80,8 +81,8 @@ def status_filter(original_urls):
# (as opposed to those that have been set with no score) # (as opposed to those that have been set with no score)
if (u.id not in scores) or (u.score and u.score < 100.0): if (u.id not in scores) or (u.score and u.score < 100.0):
urls.append(u) urls.append(u)
# if a url doesn't have a score, treat it as the highest possible # randomize list to prevent users from overloading the first mirror in the returned list
return sorted(urls, key=lambda x: x.score or 100.0) return random.shuffle(urls)
def find_mirrors(request, countries=None, protocols=None, use_status=False, def find_mirrors(request, countries=None, protocols=None, use_status=False,

View File

@ -33,7 +33,7 @@ <h3>Customized by country mirrorlist</h3>
desired protocol(s). Simply replace the contents of desired protocol(s). Simply replace the contents of
<code>/etc/pacman.d/mirrorlist</code> with your generated list. <code>/etc/pacman.d/mirrorlist</code> with your generated list.
Additionally, the mirror status data can be incorporated into the generated Additionally, the mirror status data can be incorporated into the generated
mirror list and used to pre-order the mirrors.</p> mirror list and used to only list up to date mirrors.</p>
<form id="list-generator" method="get"> <form id="list-generator" method="get">
{{ mirrorlist_form.as_div }} {{ mirrorlist_form.as_div }}

View File

@ -5,10 +5,10 @@ forget about where line breaks are happening until you are done getting the
content right, and then go back later to fix it all up. content right, and then go back later to fix it all up.
{% endcomment %}{% autoescape off %}## {% endcomment %}{% autoescape off %}##
## Arch Linux repository mirrorlist ## Arch Linux repository mirrorlist
## Sorted by mirror score from mirror status page ## Filtered by mirror score from mirror status page
## Generated on {% now "Y-m-d" %} ## Generated on {% now "Y-m-d" %}
## ##
{% for mirror_url in mirror_urls %} {% for mirror_url in mirror_urls %}
## Score: {{ mirror_url.score|floatvalue:1|default:'unknown' }}, {{ mirror_url.country.name|default:'Worldwide' }} ## {{ mirror_url.country.name|default:'Worldwide' }}
#Server = {{ mirror_url.url}}$repo/os/$arch{% endfor %} #Server = {{ mirror_url.url}}$repo/os/$arch{% endfor %}
{% endautoescape %} {% endautoescape %}