9
9
10
10
import logging
11
11
12
+ from aboutcode .pipeline import LoopProgress
12
13
from django .db .models import Q
13
14
14
15
from vulnerabilities .models import Advisory
@@ -27,7 +28,7 @@ def steps(cls):
27
28
28
29
def fill_missing_summaries (self ):
29
30
"""Find vulnerabilities without summaries and fill them using advisories with the same aliases."""
30
- vulnerabilities_qs = Vulnerability .objects .filter (summary = "" ). prefetch_related ( "aliases" )
31
+ vulnerabilities_qs = Vulnerability .objects .filter (summary = "" )
31
32
self .log (
32
33
f"Processing { vulnerabilities_qs .count ()} vulnerabilities without summaries" ,
33
34
level = logging .INFO ,
@@ -36,11 +37,13 @@ def fill_missing_summaries(self):
36
37
created_by = "nvd_importer" , summary__isnull = False
37
38
).exclude (summary = "" )
38
39
self .log (
39
- f"Found { nvd_importer_advisories .count ()} advisories from NVD importer" ,
40
+ f"Found { nvd_importer_advisories .count ()} advisories with summaries from NVD importer" ,
40
41
level = logging .INFO ,
41
42
)
42
43
43
- for vulnerability in vulnerabilities_qs .paginated ():
44
+ progress = LoopProgress (total_iterations = vulnerabilities_qs .count (), logger = self .log )
45
+
46
+ for vulnerability in progress .iter (vulnerabilities_qs .paginated ()):
44
47
aliases = vulnerability .aliases .values_list ("alias" , flat = True )
45
48
# get alias that start with CVE- with filter
46
49
alias = aliases .filter (alias__startswith = "CVE-" ).first ()
@@ -60,6 +63,7 @@ def fill_missing_summaries(self):
60
63
# Take the first matching advisory with a summary
61
64
# get the advisory that was collected the most recently
62
65
best_advisory = matching_advisories .order_by ("-date_collected" ).first ()
66
+ # Note: we filtered above to only get non-empty summaries
63
67
vulnerability .summary = best_advisory .summary
64
68
vulnerability .save ()
65
69
self .log (
0 commit comments