From 27752e7e27454ded4d0098cd6c216b2254c849c6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 13 Feb 2025 20:39:41 +0000 Subject: [PATCH] mirrors: Remove the extra network lookup function Signed-off-by: Michael Tremer --- src/buildservice/mirrors.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/buildservice/mirrors.py b/src/buildservice/mirrors.py index 250bdc82..5456535c 100644 --- a/src/buildservice/mirrors.py +++ b/src/buildservice/mirrors.py @@ -83,16 +83,12 @@ class Mirrors(base.Object): """ Returns all mirrors in random order with preferred mirrors first """ - # Lookup the client - network = self.location.lookup("%s" % address) - def __sort(mirror): # Generate some random value for each mirror r = random.random() # Add the preference score - if network: - r += mirror.is_preferred_for_network(network) + r += mirror.is_preferred_for_address(address) return r @@ -320,18 +316,15 @@ class Mirror(database.Base, database.BackendMixin, database.SoftDeleteMixin): def is_preferred_for_address(self, address): """ - Check if this mirror is preferred for this address + Returns a score of how much the mirror is preferred for this address """ # Lookup the client network = self.backend.mirrors.location.lookup("%s" % address) - # Check for the entire network - return self.is_preferred_for_network(network) + # Return if we could not find the client + if not network: + return 0 - def is_preferred_for_network(self, network): - """ - Returns a score of how much the mirror is preferred for this network. - """ first_address = ipaddress.ip_address(network.first_address) last_address = ipaddress.ip_address(network.last_address) -- 2.47.3