<commit_before>class GooglePlaceUpdate
  @queue = :google_place_queue

  def self.perform()

    if Rails.env.production?
      places = Place.where(:updated_at.lt => 1.month.ago).limit(100)
    else
      places = Place.where(:updated_at.lt => 1.month.ago).limit(10)
    end

    gp = GooglePlaces.new

    places.each do |place|

      if place.perspective_count == 0 && Question.any_of({'answers.place_id' => place.id}).count == 0
        RESQUE_LOGGER.info "#{place.name} - #{place.id}, no perspectives or answers, so delete"
        place.destroy

      elsif place.google_ref
        updatedPlace = gp.get_place(place.google_ref, false)

        oldPlace = place.clone
        if updatedPlace
          if updatedPlace.id == place.google_id
            #RESQUE_LOGGER.info "updating #{place.name}, same google ID"
            place = place.update_from_google_place(updatedPlace)
            place.save!
          elsif oldPlace.name == updatedPlace.name
            if merge_place = Place.find_by_google_id(updatedPlace.id)
              #weird case where changing to already existing id
              RESQUE_LOGGER.info "updating #{place.name}, existing google ID, need to merge #{oldPlace.name} and #{merge_place.name} to #{updatedPlace.name}"
            else
              RESQUE_LOGGER.info "updating #{place.name}, updated google ID, same name"
              place = place.update_from_google_place(updatedPlace)
              place.save!
            end
          else
            if merge_place = Place.find_by_google_id(updatedPlace.id)
              #weird case where changing to already existing id
              RESQUE_LOGGER.info "updating #{place.name}, existing google ID, need to merge #{oldPlace.name} and #{merge_place.name} to #{updatedPlace.name}"
              #place.save
            else
              RESQUE_LOGGER.info "updating #{place.name}, updated google ID, #{oldPlace.name} != #{updatedPlace.name}"
            end
          end
        else
          RESQUE_LOGGER.info "didn't get place back for #{place.name} - #{place.id}"
        end
        sleep(2)
      end
    end
  end

end
<commit_msg>CHA-17, save the place if we dont' get anything back, bump up to 300, reduce logging to exception cases<commit_after>class GooglePlaceUpdate
  @queue = :google_place_queue

  def self.perform()

    if Rails.env.production?
      places = Place.where(:updated_at.lt => 1.month.ago).limit(300)
    else
      places = Place.where(:updated_at.lt => 1.month.ago).limit(10)
    end

    gp = GooglePlaces.new

    places.each do |place|

      if place.perspective_count == 0 && Question.any_of({'answers.place_id' => place.id}).count == 0
        #RESQUE_LOGGER.info "#{place.name} - #{place.id}, no perspectives or answers, so delete"
        place.destroy

      elsif place.google_ref
        updatedPlace = gp.get_place(place.google_ref, false)

        oldPlace = place.clone
        if updatedPlace
          if updatedPlace.id == place.google_id
            #RESQUE_LOGGER.info "updating #{place.name}, same google ID"
            place = place.update_from_google_place(updatedPlace)
            place.save!
          elsif oldPlace.name == updatedPlace.name
            if merge_place = Place.find_by_google_id(updatedPlace.id)
              #weird case where changing to already existing id
              RESQUE_LOGGER.info "updating #{place.name}, existing google ID, need to merge #{oldPlace.name} and #{merge_place.name} to #{updatedPlace.name}"
            else
              #RESQUE_LOGGER.info "updating #{place.name}, updated google ID, same name"
              place = place.update_from_google_place(updatedPlace)
              place.save!
            end
          else
            if merge_place = Place.find_by_google_id(updatedPlace.id)
              #weird case where changing to already existing id
              RESQUE_LOGGER.info "updating #{place.name}, existing google ID, need to merge #{oldPlace.name} and #{merge_place.name} to #{updatedPlace.name}"
              #place.save
            else
              RESQUE_LOGGER.info "updating #{place.name}, updated google ID, #{oldPlace.name} != #{updatedPlace.name}"
            end
          end
        else
          RESQUE_LOGGER.info "didn't get place back for #{place.name} - #{place.id}"
          place.save #not sure what to do with these yet, so just renew their lease on life
        end
        sleep(2)
      end
    end
  end

end

{'fraction_non_alphanumeric': 0.09842696629213483, 'fraction_numerical': 0.0056179775280898875, 'mean_word_length': 2.2897265336289725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7371449', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1274, 'n_words': 338}