Sha256: 27c006f1f6b07b985164f276e8dab0aba6a3ab2acf390e89d5b0a78dbcc32e19

Contents?: true

Size: 1.64 KB

Versions: 17

Compression:

Stored size: 1.64 KB

Contents

module MilestoneSynchronizer


  def fetch_all
    Houston.benchmark "GET All Milestones" do
      synchronize ticket_tracker.all_milestones
    end
  end

  def fetch_open
    Houston.benchmark "GET Open Milestones" do
      synchronize ticket_tracker.open_milestones
    end
  end


  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


private

  def ticket_tracker
    project.ticket_tracker
  end

  def project
    proxy_association.owner
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre app/concerns/milestone_synchronizer.rb
houston-core-0.7.0 app/concerns/milestone_synchronizer.rb
houston-core-0.7.0.beta4 app/concerns/milestone_synchronizer.rb
houston-core-0.7.0.beta3 app/concerns/milestone_synchronizer.rb
houston-core-0.7.0.beta2 app/concerns/milestone_synchronizer.rb
houston-core-0.7.0.beta app/concerns/milestone_synchronizer.rb
houston-core-0.6.3 app/concerns/milestone_synchronizer.rb
houston-core-0.6.2 app/concerns/milestone_synchronizer.rb
houston-core-0.6.1 app/concerns/milestone_synchronizer.rb
houston-core-0.6.0 app/concerns/milestone_synchronizer.rb
houston-core-0.5.6 app/concerns/milestone_synchronizer.rb
houston-core-0.5.5 app/concerns/milestone_synchronizer.rb
houston-core-0.5.4 app/concerns/milestone_synchronizer.rb
houston-core-0.5.3 app/concerns/milestone_synchronizer.rb
houston-core-0.5.2 app/concerns/milestone_synchronizer.rb
houston-core-0.5.1 app/concerns/milestone_synchronizer.rb
houston-core-0.5.0 app/concerns/milestone_synchronizer.rb