<commit_before>##
# Controller to export subscriptions data

class Api::OpmlExportsController < ApplicationController

  before_filter :authenticate_user!

  respond_to :html, only: [:create]
  respond_to :json, only: [:show, :update, :download]

  ##
  # Return JSON indicating the state of the "export subscriptions" process for the current user

  def show
    if OpmlExportJobState.exists? user_id: current_user.id
      @opml_export_job_state = OpmlExportJobState.find_by user_id: current_user.id
    else
      Rails.logger.warn "User #{current_user.id} - #{current_user.email} has no OpmlExportJobState, creating one with state NONE"
      @opml_export_job_state = current_user.create_opml_export_job_state state: OpmlExportJobState::NONE
    end

    # If opml export state has not changed, return a 304
    if stale? etag: EtagCalculator.etag(@opml_export_job_state.updated_at), last_modified: @opml_export_job_state.updated_at
      Rails.logger.debug "OpmlExportJobState for user #{current_user.id} - #{current_user.email}: id #{@opml_export_job_state.try :id}, state #{@opml_export_job_state.try :state}"
      respond_with @opml_export_job_state
    end
  rescue => e
    handle_error e
  end

  ##
  # Export a user's subscriptions in OPML format.

  def create
    current_user.export_subscriptions
  rescue => e
    Rails.logger.error "Error exporting OPML data for user #{current_user.email} - #{current_user.name}"
    Rails.logger.error e.message
    Rails.logger.error e.backtrace
    current_user.create_opml_export_job_state state: OpmlExportJobState::ERROR
  ensure
    redirect_to read_path
  end
<commit_msg>Minor change in formatting<commit_after>##
# Controller to export subscriptions data

class Api::OpmlExportsController < ApplicationController

  before_filter :authenticate_user!

  respond_to :html, only: [:create]
  respond_to :json, only: [:show, :update, :download]

  ##
  # Return JSON indicating the state of the "export subscriptions" process for the current user

  def show
    if OpmlExportJobState.exists? user_id: current_user.id
      @opml_export_job_state = OpmlExportJobState.find_by user_id: current_user.id
    else
      Rails.logger.warn "User #{current_user.id} - #{current_user.email} has no OpmlExportJobState, creating one with state NONE"
      @opml_export_job_state = current_user.create_opml_export_job_state state: OpmlExportJobState::NONE
    end

    # If opml export state has not changed, return a 304
    if stale? etag: EtagCalculator.etag(@opml_export_job_state.updated_at),
              last_modified: @opml_export_job_state.updated_at
      Rails.logger.debug "OpmlExportJobState for user #{current_user.id} - #{current_user.email}: id #{@opml_export_job_state.try :id}, state #{@opml_export_job_state.try :state}"
      respond_with @opml_export_job_state
    end
  rescue => e
    handle_error e
  end

  ##
  # Export a user's subscriptions in OPML format.

  def create
    current_user.export_subscriptions
  rescue => e
    Rails.logger.error "Error exporting OPML data for user #{current_user.email} - #{current_user.name}"
    Rails.logger.error e.message
    Rails.logger.error e.backtrace
    current_user.create_opml_export_job_state state: OpmlExportJobState::ERROR
  ensure
    redirect_to read_path
  end

{'fraction_non_alphanumeric': 0.08199210446401457, 'fraction_numerical': 0.0018220467658669906, 'mean_word_length': 4.382352941176471, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3305100', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1050, 'n_words': 265}