@@ -80,10 +80,13 @@ def collect_ssvc_data(self):
8080 advisory_map [alias .alias ].add (adv )
8181
8282 existing_ssvc = {
83- s .source_advisory_id : s
83+ ( s .source_advisory_id , s . vector ) : s
8484 for s in SSVC .objects .filter (source_advisory_id__in = [a .id for a in advisories ])
8585 }
8686
87+ self .log (f"Existing SSVC rows found: { len (existing_ssvc )} " )
88+ self .log (f"Advisories to process: { len (advisories )} " )
89+
8790 to_create = []
8891 to_update = []
8992
@@ -99,7 +102,9 @@ def collect_ssvc_data(self):
99102 if not (ssvc_tree and decision ):
100103 continue
101104
102- existing = existing_ssvc .get (advisory .id )
105+ key = (advisory .id , ssvc_vector )
106+
107+ existing = existing_ssvc .get (key )
103108
104109 if existing :
105110 existing .options = ssvc_tree
@@ -131,33 +136,31 @@ def collect_ssvc_data(self):
131136 )
132137
133138 # Refresh newly created IDs
134- created_ssvc = {
135- s . source_advisory_id : s
136- for s in SSVC .objects .filter (source_advisory_id__in = [a .id for a in advisories ])
137- }
139+ created_ssvc = defaultdict ( list )
140+
141+ for s in SSVC .objects .filter (source_advisory_id__in = [a .id for a in advisories ]):
142+ created_ssvc [ s . source_advisory_id ]. append ( s )
138143
139144 through_model = SSVC .related_advisories .through
140145
141146 through_rows = []
142147
143148 for advisory in advisories :
144- ssvc_obj = created_ssvc .get (advisory .id )
145-
146- if not ssvc_obj :
147- continue
149+ ssvc_objs = created_ssvc .get (advisory .id , [])
148150
149151 related = advisory_map .get (advisory .advisory_id , set ())
150152
151- for related_adv in related :
152- if related_adv .id == advisory .id :
153- continue
153+ for ssvc_obj in ssvc_objs :
154+ for related_adv in related :
155+ if related_adv .id == advisory .id :
156+ continue
154157
155- through_rows .append (
156- through_model (
157- ssvc_id = ssvc_obj .id ,
158- advisoryv2_id = related_adv .id ,
158+ through_rows .append (
159+ through_model (
160+ ssvc_id = ssvc_obj .id ,
161+ advisoryv2_id = related_adv .id ,
162+ )
159163 )
160- )
161164
162165 through_model .objects .bulk_create (
163166 through_rows ,
0 commit comments