]> git.ipfire.org Git - pbs.git/commitdiff
mirrors: Remove the extra network lookup function
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 Feb 2025 20:39:41 +0000 (20:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 Feb 2025 20:39:41 +0000 (20:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/mirrors.py

index 250bdc82ed2b07ceba9ce57379b9451dc1918955..5456535c91051bb8c97e953ad11e3d21c101738a 100644 (file)
@@ -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)