@@ -148,34 +148,12 @@ def sync_packages(packages)
148148 error "Failed to query OSV API: #{ e . message } "
149149 end
150150
151- # Collect all unique vuln IDs and fetch full details
152- vuln_ids = results . flatten . map { |v | v [ "id" ] } . uniq
153- vuln_ids . each do |vuln_id |
154- next if Models ::Vulnerability . first ( id : vuln_id ) &.vulnerability_packages &.any?
155-
156- begin
157- full_vuln = client . get_vulnerability ( vuln_id )
158- Models ::Vulnerability . from_osv ( full_vuln )
159- rescue OsvClient ::ApiError => e
160- $stderr. puts "Warning: Failed to fetch vulnerability #{ vuln_id } : #{ e . message } " unless Git ::Pkgs . quiet
161- end
162- end
151+ fetch_vulnerability_details ( client , results )
163152
164- # Update package sync timestamps
165153 packages . each do |pkg |
166154 bib_ecosystem = Ecosystems . from_osv ( pkg [ :ecosystem ] )
167155 purl = Ecosystems . generate_purl ( bib_ecosystem , pkg [ :name ] )
168-
169- if purl
170- Models ::Package . update_or_create (
171- { purl : purl } ,
172- {
173- ecosystem : bib_ecosystem ,
174- name : pkg [ :name ] ,
175- vulns_synced_at : Time . now
176- }
177- )
178- end
156+ mark_package_synced ( purl , bib_ecosystem , pkg [ :name ] ) if purl
179157 end
180158 end
181159
@@ -207,33 +185,36 @@ def ensure_vulns_synced
207185 end . compact
208186
209187 results = client . query_batch ( queries )
188+ fetch_vulnerability_details ( client , results )
210189
211- # Collect all unique vuln IDs and fetch full details
212- vuln_ids = results . flatten . map { |v | v [ "id" ] } . uniq
213- vuln_ids . each do |vuln_id |
214- next if Models ::Vulnerability . first ( id : vuln_id ) &.vulnerability_packages &.any?
215-
216- begin
217- full_vuln = client . get_vulnerability ( vuln_id )
218- Models ::Vulnerability . from_osv ( full_vuln )
219- rescue OsvClient ::ApiError => e
220- $stderr. puts "Warning: Failed to fetch vulnerability #{ vuln_id } : #{ e . message } " unless Git ::Pkgs . quiet
221- end
222- end
223-
224- # Update package sync timestamps
225190 batch . each do |pkg |
226191 purl = Ecosystems . generate_purl ( pkg . ecosystem , pkg . name )
227- next unless purl
192+ mark_package_synced ( purl , pkg . ecosystem , pkg . name ) if purl
193+ end
194+ end
195+ end
196+
197+ def fetch_vulnerability_details ( client , results )
198+ vuln_ids = results . flatten . map { |v | v [ "id" ] } . uniq
199+ vuln_ids . each do |vuln_id |
200+ next if Models ::Vulnerability . first ( id : vuln_id ) &.vulnerability_packages &.any?
228201
229- Models ::Package . update_or_create (
230- { purl : purl } ,
231- { ecosystem : pkg . ecosystem , name : pkg . name , vulns_synced_at : Time . now }
232- )
202+ begin
203+ full_vuln = client . get_vulnerability ( vuln_id )
204+ Models ::Vulnerability . from_osv ( full_vuln )
205+ rescue OsvClient ::ApiError => e
206+ $stderr. puts "Warning: Failed to fetch vulnerability #{ vuln_id } : #{ e . message } " unless Git ::Pkgs . quiet
233207 end
234208 end
235209 end
236210
211+ def mark_package_synced ( purl , ecosystem , name )
212+ Models ::Package . update_or_create (
213+ { purl : purl } ,
214+ { ecosystem : ecosystem , name : name , vulns_synced_at : Time . now }
215+ )
216+ end
217+
237218 def format_commit_info ( commit )
238219 return nil unless commit
239220
0 commit comments