Module: MilestoneSynchronizer
- Defined in:
- app/concerns/milestone_synchronizer.rb
Instance Method Summary collapse
Instance Method Details
#fetch_all ⇒ Object
4 5 6 7 8 |
# File 'app/concerns/milestone_synchronizer.rb', line 4 def fetch_all Houston.benchmark "GET All Milestones" do synchronize ticket_tracker.all_milestones end end |
#fetch_open ⇒ Object
10 11 12 13 14 |
# File 'app/concerns/milestone_synchronizer.rb', line 10 def fetch_open Houston.benchmark "GET Open Milestones" do synchronize ticket_tracker.open_milestones end end |
#synchronize(unsynchronized_milestones) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/concerns/milestone_synchronizer.rb', line 17 def synchronize(unsynchronized_milestones) unsynchronized_milestones = unsynchronized_milestones.reject(&:nil?) return [] if unsynchronized_milestones.empty? Houston.benchmark("[milestones.synchronize] synchronizing with local milestones") do remote_ids = unsynchronized_milestones.map(&:remote_id) milestones = where(remote_id: remote_ids) unsynchronized_milestones.map do |unsynchronized_milestone| milestone = milestones.detect { |milestone| milestone.remote_id == unsynchronized_milestone.remote_id } attributes = unsynchronized_milestone.attributes if milestone # This is essentially a call to update_attributes, # but I broke it down so that we don't begin a # transaction if we don't have any changes to save. # This is pretty much just to reduce log verbosity. milestone.assign_attributes(attributes) milestone.save if milestone.changed? else milestone = create(attributes) end # There's no reason why this shouldn't be set, # but in order to reduce a bunch of useless hits # to the cache and a bunch of log output... milestone.project = project milestone end end end |