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>
This commit is contained in:
parent
baaa14dfc0
commit
8d21e9f4b1
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user