summaryrefslogtreecommitdiffstats
path: root/mirrors/management/commands
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-04-29 01:25:37 +0200
committerDan McGee <dan@archlinux.org>2012-04-29 01:25:37 +0200
commit8d21e9f4b1d5a31880f9973d758de9becc90eb39 (patch)
tree789ef138de1e4e30319275facd87e35a1f1f4afc /mirrors/management/commands
parentbaaa14dfc06cf8c381363883ebf4fd805b348e34 (diff)
downloadarchweb-8d21e9f4b1d5a31880f9973d758de9becc90eb39.tar.gz
archweb-8d21e9f4b1d5a31880f9973d758de9becc90eb39.tar.xz
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 <dan@archlinux.org>
Diffstat (limited to 'mirrors/management/commands')
-rw-r--r--mirrors/management/commands/mirrorresolv.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/mirrors/management/commands/mirrorresolv.py b/mirrors/management/commands/mirrorresolv.py
index 4e812f2..0370f8e 100644
--- a/mirrors/management/commands/mirrorresolv.py
+++ b/mirrors/management/commands/mirrorresolv.py
@@ -41,13 +41,19 @@ def resolve_mirrors():
logger.debug("requesting list of mirror URLs")
for mirrorurl in MirrorUrl.objects.filter(mirror__active=True):
try:
+ # save old values, we can skip no-op updates this way
+ oldvals = (mirrorurl.has_ipv4, mirrorurl.has_ipv6)
logger.debug("resolving %3i (%s)", mirrorurl.id, 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)
- mirrorurl.save(force_update=True)
+ # 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)
+ mirrorurl.save(force_update=True)
except socket.error, e:
logger.warn("error resolving %s: %s", mirrorurl.hostname, e)