Skip to content

Commit d4ed139

Browse files
committed
add .iterator() to large queryset loops
1 parent 3f4cb69 commit d4ed139

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

hosts/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def find_host_updates(host_id):
3333
def find_all_host_updates():
3434
""" Task to find updates for all hosts
3535
"""
36-
for host in Host.objects.all():
36+
for host in Host.objects.all().iterator():
3737
find_host_updates.delay(host.id)
3838

3939

sbin/patchman

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def process_reports(host=None, force=False):
352352

353353
info_message(text=text)
354354

355-
for report in reports:
355+
for report in reports.iterator():
356356
report.process(find_updates=False)
357357

358358

security/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def update_cves():
5050

5151
if cache.add(lock_key, 'true', lock_expire):
5252
try:
53-
for cve in CVE.objects.all():
53+
for cve in CVE.objects.all().iterator():
5454
update_cve.delay(cve.id)
5555
finally:
5656
cache.delete(lock_key)
@@ -87,7 +87,7 @@ def update_cwes():
8787

8888
if cache.add(lock_key, 'true', lock_expire):
8989
try:
90-
for cwe in CWE.objects.all():
90+
for cwe in CWE.objects.all().iterator():
9191
update_cwe.delay(cwe.id)
9292
finally:
9393
cache.delete(lock_key)

security/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def update_cves(cve_id=None, fetch_nist_data=False):
4242
cve = CVE.objects.get(cve_id=cve_id)
4343
cve.fetch_cve_data(fetch_nist_data, sleep_secs=0)
4444
else:
45-
for cve in CVE.objects.all():
45+
for cve in CVE.objects.all().iterator():
4646
cve.fetch_cve_data(fetch_nist_data)
4747

4848

@@ -56,7 +56,7 @@ def update_cwes(cve_id=None):
5656
cwes = cve.cwes.all()
5757
else:
5858
cwes = CWE.objects.all()
59-
for cwe in cwes:
59+
for cwe in cwes.iterator():
6060
cwe.fetch_cwe_data()
6161

6262

0 commit comments

Comments
 (0)