Skip to content

Commit

Permalink
Handle invalid input types for existing_packages query by ensuring va…
Browse files Browse the repository at this point in the history
…lid array of strings
  • Loading branch information
andrew committed Nov 10, 2024
1 parent 383d2d5 commit 8d1a205
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/models/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ def recently_updated_package_names
end

def recently_updated_package_names_excluding_recently_synced
puts name
existing_packages = packages.where(name: recently_updated_package_names)
missing_names = recently_updated_package_names - existing_packages.map(&:name)
existing_packages.where("last_synced_at < ?", 10.minutes.ago).pluck(:name) + missing_names
package_names = Array(recently_updated_package_names).compact.map(&:to_s)
return [] if package_names.empty?
existing_packages = packages.where(name: package_names)
existing_package_names = existing_packages.map(&:name).compact.map(&:to_s)

missing_names = package_names - existing_package_names

outdated_package_names = existing_packages
.where("last_synced_at < ?", 10.minutes.ago)
.pluck(:name)
.compact

outdated_package_names.map(&:to_s) + missing_names
end

def existing_package_names
Expand Down

0 comments on commit 8d1a205

Please sign in to comment.