Skip to content

Commit a9bc4ae

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

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

hosts/tasks.py

Lines changed: 3 additions & 3 deletions
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

@@ -43,7 +43,7 @@ def find_all_host_updates_homogenous():
4343
"""
4444
updated_hosts = []
4545
ts = get_datetime_now()
46-
for host in Host.objects.all():
46+
for host in Host.objects.all().iterator():
4747
if host not in updated_hosts:
4848
host.find_updates()
4949
host.updated_at = ts
@@ -61,7 +61,7 @@ def find_all_host_updates_homogenous():
6161
updates = host.updates.all()
6262

6363
phosts = []
64-
for fhost in filtered_hosts:
64+
for fhost in filtered_hosts.iterator():
6565
frepos = set(fhost.repos.all())
6666
if repos != frepos:
6767
continue

sbin/patchman

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def host_updates_alt(host=None):
164164
updated_hosts = []
165165
hosts = get_hosts(host, 'Finding updates')
166166
ts = get_datetime_now()
167-
for host in hosts:
167+
for host in hosts.iterator():
168168
info_message(text=str(host))
169169
if host not in updated_hosts:
170170
host.find_updates()
@@ -183,7 +183,7 @@ def host_updates_alt(host=None):
183183
updates = host.updates.all()
184184

185185
phosts = []
186-
for fhost in filtered_hosts:
186+
for fhost in filtered_hosts.iterator():
187187

188188
frepos = set(fhost.repos.all())
189189
rdiff = repos.difference(frepos)
@@ -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)