Skip to content

Commit

Permalink
Merge pull request #2459 from MushroomObserver/jdc-2458-speed-up-fres…
Browse files Browse the repository at this point in the history
…h_import

Speed up prior import validators
  • Loading branch information
JoeCohen authored Oct 5, 2024
2 parents 2207695 + 102acfd commit 42dd7eb
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions app/controllers/observations/inat_imports_controller_validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ def list_within_size_limits?
end

def fresh_import?
previous_imports =
inat_id_list.each_with_object([]) do |inat_id, ary|
ary << Observation.find_by(inat_id: inat_id)
end
previous_imports = Observation.where(inat_id: inat_id_list)
return true if previous_imports.none?

previous_imports.each do |import|
Expand All @@ -66,13 +63,10 @@ def inat_id_list
end

def unmirrored?
previously_mirrored =
inat_id_list.each_with_object([]) do |inat_id, ary|
mirrored = Observation.notes_include(
"Mirrored on iNaturalist as <a href=\"https://www.inaturalist.org/observations/#{inat_id}\">"
).first
ary << mirrored if mirrored
end
conditions = inat_id_list.map do |inat_id|
Observation[:notes].matches("%Mirrored on iNaturalist as <a href=\"https://www.inaturalist.org/observations/#{inat_id}\">%")
end
previously_mirrored = Observation.where(conditions.inject(:or)).to_a
return true if previously_mirrored.blank?

previously_mirrored.each do |obs|
Expand Down

0 comments on commit 42dd7eb

Please sign in to comment.