<commit_before>class Api::AttemptStopsController < Api::BaseController
  def update
    attempt_stop = attempt.attempt_stops.where(stop_id: params[:id]).first!

    if params[:stop][:visited]
      attempt_stop.visited_at ||= Time.current
    else
      attempt_stop.visited_at = nil
    end

    if attempt_stop.save
      render json: AttemptStopRepresenter.new(attempt_stop)
    else
      error = {
        error: "Couldn't update AttemptStop",
        errors: attempt_stop.errors
      }
      render json: error, status: :bad_request
    end
  end

  private def attempt
    @attempt ||= current_player.attempts.in_progress.first
  end
end
<commit_msg>Be more resilient with stop visit calls<commit_after>class Api::AttemptStopsController < Api::BaseController
  def update
    attempt_stop = current_player.attempt_stops.find_by!(stop_id: params[:id])

    if params[:stop][:visited]
      attempt_stop.visited_at ||= Time.current
    else
      attempt_stop.visited_at = nil
    end

    if attempt_stop.save
      render json: AttemptStopRepresenter.new(attempt_stop)
    else
      error = {
        error: "Couldn't update AttemptStop",
        errors: attempt_stop.errors
      }
      render json: error, status: :bad_request
    end
  end
end

{'fraction_non_alphanumeric': 0.08591885441527446, 'fraction_numerical': 0.0, 'mean_word_length': 3.1518151815181517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5892465', 'n_tokens_mistral': 400, 'n_tokens_neox': 380, 'n_words': 86}