@@ -36,26 +36,9 @@ class MarkUnfurlVersionRangePipeline(VulnerableCodePipeline):
3636
3737 @classmethod
3838 def steps (cls ):
39- return (
40- cls .mark_all_impacts_unfurled_successfully ,
41- cls .mark_all_impacts_unfurl_attempted ,
42- )
43-
44- def mark_all_impacts_unfurled_successfully (self ):
45- impacted_packages = ImpactedPackage .objects .all ()
46- while True :
47- advisory_ids = list (
48- latest_advisories_with_all_impacts_unfurled_successfully (
49- impacted_packages = impacted_packages
50- )[:100 ]
51- )
52-
53- if not advisory_ids :
54- break
55-
56- complete_advisories_import (advisory_ids = advisory_ids , success = True )
39+ return (cls .mark_all_impacts_unfurled ,)
5740
58- def mark_all_impacts_unfurl_attempted (self ):
41+ def mark_all_impacts_unfurled (self ):
5942 impacted_packages = ImpactedPackage .objects .all ()
6043 advisories_qs = latest_advisories_with_all_impacts_unfurled_attempted (
6144 impacted_packages = impacted_packages
@@ -64,18 +47,26 @@ def mark_all_impacts_unfurl_attempted(self):
6447 batch_size = 100
6548 batch = []
6649
50+ successful_qs = latest_advisories_with_all_impacts_unfurled_successfully (
51+ impacted_packages = impacted_packages ,
52+ )
53+
6754 for advisory_id in advisories_qs .iterator (chunk_size = 100 ):
6855 batch .append (advisory_id )
6956
7057 if len (batch ) >= batch_size :
58+ successful_ids = set (successful_qs .filter (id__in = list (batch )))
59+
7160 complete_advisories_import (
72- advisory_ids = list (batch ),
61+ advisory_ids = list (batch ), successful_advisory_ids = successful_ids
7362 )
7463 batch .clear ()
7564
7665 if batch :
66+ successful_ids = set (successful_qs .filter (id__in = list (batch )))
67+
7768 complete_advisories_import (
78- advisory_ids = list (batch ),
69+ advisory_ids = list (batch ), successful_advisory_ids = successful_ids
7970 )
8071
8172
@@ -121,15 +112,17 @@ def latest_advisories_with_all_impacts_unfurled_attempted(
121112
122113
123114@transaction .atomic
124- def complete_advisories_import (advisory_ids , success = False ):
115+ def complete_advisories_import (advisory_ids , successful_advisory_ids = [] ):
125116 if not advisory_ids :
126117 return
127118
128119 AdvisoryV2 .objects .filter (id__in = advisory_ids ).update (_all_impacts_unfurled = True )
129120
130- if success :
131- AdvisoryV2 .objects .filter (id__in = advisory_ids ).update (
132- _all_impacts_unfurled_successfully = True
121+ if successful_advisory_ids :
122+ AdvisoryV2 .objects .filter (
123+ id__in = successful_advisory_ids ,
124+ ).update (
125+ _all_impacts_unfurled_successfully = True ,
133126 )
134127
135128 affecting_package_ids = set (
0 commit comments