@@ -34,19 +34,38 @@ def run
3434 return
3535 end
3636
37+ # Batch fetch all changes for current dependencies
38+ snapshot_keys = snapshots . map { |s | [ s . name , s . manifest_id ] } . to_set
39+ manifest_ids = snapshots . map ( &:manifest_id ) . uniq
40+ names = snapshots . map ( &:name ) . uniq
41+
42+ all_changes = Models ::DependencyChange
43+ . includes ( :commit )
44+ . where ( manifest_id : manifest_ids , name : names )
45+ . to_a
46+
47+ # Group by (name, manifest_id) and find latest by committed_at
48+ latest_by_key = { }
49+ all_changes . each do |change |
50+ key = [ change . name , change . manifest_id ]
51+ next unless snapshot_keys . include? ( key )
52+
53+ existing = latest_by_key [ key ]
54+ if existing . nil? || change . commit . committed_at > existing . commit . committed_at
55+ latest_by_key [ key ] = change
56+ end
57+ end
58+
3759 # Find last update for each dependency
3860 outdated_data = [ ]
61+ now = Time . now
3962
4063 snapshots . each do |snapshot |
41- last_change = Models ::DependencyChange
42- . includes ( :commit )
43- . where ( name : snapshot . name , manifest : snapshot . manifest )
44- . order ( "commits.committed_at DESC" )
45- . first
64+ last_change = latest_by_key [ [ snapshot . name , snapshot . manifest_id ] ]
4665
4766 next unless last_change
4867
49- days_since_update = ( ( Time . now - last_change . commit . committed_at ) / 86400 ) . to_i
68+ days_since_update = ( ( now - last_change . commit . committed_at ) / 86400 ) . to_i
5069
5170 outdated_data << {
5271 name : snapshot . name ,
0 commit comments