use 1 transaction for the whole faults command db update
hopefully this is much faster than the default behaviour which does 1 transaction per save(), so the database is not locked such a long time.
This commit is contained in:
parent
3cf5e6ff96
commit
cafaeeb64e
@ -5,6 +5,7 @@ dealing with the fault counters and available/abuse/abuse_blocked flags
|
|||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
from nsupdate.main.models import Host
|
from nsupdate.main.models import Host
|
||||||
|
|
||||||
@ -73,31 +74,32 @@ class Command(BaseCommand):
|
|||||||
reset_abuse = options['reset_abuse']
|
reset_abuse = options['reset_abuse']
|
||||||
reset_abuse_blocked = options['reset_abuse_blocked']
|
reset_abuse_blocked = options['reset_abuse_blocked']
|
||||||
flag_abuse = options['flag_abuse']
|
flag_abuse = options['flag_abuse']
|
||||||
for h in Host.objects.all():
|
with transaction.commit_on_success(): # TODO: after requiring django 1.6, use atomic()
|
||||||
if show_client or show_server:
|
for h in Host.objects.all():
|
||||||
output = u""
|
if show_client or show_server:
|
||||||
if show_client:
|
output = u""
|
||||||
output += u"%-6d " % h.client_faults
|
if show_client:
|
||||||
if show_server:
|
output += u"%-6d " % h.client_faults
|
||||||
output += u"%-6d " % h.server_faults
|
if show_server:
|
||||||
output += u"%s %s\n" % (h.created_by.username, h.get_fqdn(), )
|
output += u"%-6d " % h.server_faults
|
||||||
self.stdout.write(output)
|
output += u"%s %s\n" % (h.created_by.username, h.get_fqdn(), )
|
||||||
if (flag_abuse is not None or reset_client or reset_server or
|
self.stdout.write(output)
|
||||||
reset_available or reset_abuse or reset_abuse_blocked):
|
if (flag_abuse is not None or reset_client or reset_server or
|
||||||
if flag_abuse is not None:
|
reset_available or reset_abuse or reset_abuse_blocked):
|
||||||
if h.client_faults > flag_abuse:
|
if flag_abuse is not None:
|
||||||
h.abuse = True
|
if h.client_faults > flag_abuse:
|
||||||
self.stdout.write("setting abuse flag for host %s (created by %s, client faults: %d)\n" % (
|
h.abuse = True
|
||||||
h.get_fqdn(), h.created_by, h.client_faults))
|
self.stdout.write("setting abuse flag for host %s (created by %s, client faults: %d)\n" % (
|
||||||
|
h.get_fqdn(), h.created_by, h.client_faults))
|
||||||
|
h.client_faults = 0
|
||||||
|
if reset_client:
|
||||||
h.client_faults = 0
|
h.client_faults = 0
|
||||||
if reset_client:
|
if reset_server:
|
||||||
h.client_faults = 0
|
h.server_faults = 0
|
||||||
if reset_server:
|
if reset_available:
|
||||||
h.server_faults = 0
|
h.available = True
|
||||||
if reset_available:
|
if reset_abuse:
|
||||||
h.available = True
|
h.abuse = False
|
||||||
if reset_abuse:
|
if reset_abuse_blocked:
|
||||||
h.abuse = False
|
h.abuse_blocked = False
|
||||||
if reset_abuse_blocked:
|
h.save()
|
||||||
h.abuse_blocked = False
|
|
||||||
h.save()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user