diff options
authorDan McGee <>2012-04-28 18:25:37 -0500
committerDan McGee <>2012-04-28 18:25:37 -0500
commit8d21e9f4b1d5a31880f9973d758de9becc90eb39 (patch)
parentbaaa14dfc06cf8c381363883ebf4fd805b348e34 (diff)
mirrorresolv: only run update query if values changed
98% of the time, we won't need to update the existing values as it will be the same as the prior run of this command. Do a quick check of the old and new values and don't send anything to the database if there is no need for an update. Signed-off-by: Dan McGee <>
1 files changed, 7 insertions, 1 deletions
diff --git a/mirrors/management/commands/ b/mirrors/management/commands/
index 4e812f2d..0370f8ed 100644
--- a/mirrors/management/commands/
+++ b/mirrors/management/commands/
@@ -41,13 +41,19 @@ def resolve_mirrors():
logger.debug("requesting list of mirror URLs")
for mirrorurl in MirrorUrl.objects.filter(mirror__active=True):
+ # save old values, we can skip no-op updates this way
+ oldvals = (mirrorurl.has_ipv4, mirrorurl.has_ipv6)
logger.debug("resolving %3i (%s)",, mirrorurl.hostname)
families = mirrorurl.address_families()
mirrorurl.has_ipv4 = socket.AF_INET in families
mirrorurl.has_ipv6 = socket.AF_INET6 in families
logger.debug("%s: v4: %s v6: %s", mirrorurl.hostname,
mirrorurl.has_ipv4, mirrorurl.has_ipv6)
+ # now check new values, only update if new != old
+ newvals = (mirrorurl.has_ipv4, mirrorurl.has_ipv6)
+ if newvals != oldvals:
+ logger.debug("values changed for %s", mirrorurl)
except socket.error, e:
logger.warn("error resolving %s: %s", mirrorurl.hostname, e)