<commit_before>class Admin::ActivitiesController < Admin::AdminController
  before_filter :get_search_params, :only => :show
  before_filter :get_changes, :only => :show
  before_filter :paginate, :only => :show

  def show
  end

  def update
    change = ChangesHistoryRecord.find(params[:id])
    change.update_attributes!(params[:changes_history_record])

    render :nothing => true  and return if request.xhr?
    redirect_to admin_activity_path
  end

  def get_search_params
    search_params = {
      'who'        => nil,
      'what_type'  => nil,
      'when_start' => nil,
      'when_end'   => nil
    }.
    merge(process_dates(params[:search]) || {})

    @search = OpenStruct.new(search_params)
  end
  private :get_search_params

  def get_changes
    @changes = ChangesHistoryRecord.search(@search)

    @project      = Project.find(params[:project_id])           if params[:project_id].present?
    @organization = Organization.find(params[:organization_id]) if params[:organization_id].present?

    @changes = @project.changes_history_records      if @project
    @changes = @organization.changes_history_records if @organization
  end
  private :get_changes

  def paginate
    @changes = @changes.order('changes_history_records.when DESC').paginate :per_page => 20, :page => params[:page]
  end
  private :paginate

  def process_dates(hash)
    return if hash.blank?
    %w(when_start when_end).each do |attribute|
      hash[attribute] = Date.new(hash[attribute + '(1i)'].to_i, hash[attribute + '(2i)'].to_i, hash[attribute + '(3i)'].to_i) rescue nil
    end
    hash
  end
  private :process_dates

end<commit_msg>Remove unnecessary load of changes_history table for certain routes<commit_after>class Admin::ActivitiesController < Admin::AdminController
  before_filter :get_search_params, :only => :show
  before_filter :get_changes, :only => :show
  before_filter :paginate, :only => :show

  def show
  end

  def update
    change = ChangesHistoryRecord.find(params[:id])
    change.update_attributes!(params[:changes_history_record])

    render :nothing => true  and return if request.xhr?
    redirect_to admin_activity_path
  end

  def get_search_params
    search_params = {
      'who'        => nil,
      'what_type'  => nil,
      'when_start' => nil,
      'when_end'   => nil
    }.
    merge(process_dates(params[:search]) || {})

    @search = OpenStruct.new(search_params)
  end
  private :get_search_params

  def get_changes

    @project      = Project.find(params[:project_id])           if params[:project_id].present?
    @organization = Organization.find(params[:organization_id]) if params[:organization_id].present?

    @changes = @project.changes_history_records      if @project
    @changes = @organization.changes_history_records if @organization
    @changes ||= ChangesHistoryRecord.search(@search)

  end
  private :get_changes

  def paginate
    @changes = @changes.order('changes_history_records.when DESC').paginate :per_page => 20, :page => params[:page]
  end
  private :paginate

  def process_dates(hash)
    return if hash.blank?
    %w(when_start when_end).each do |attribute|
      hash[attribute] = Date.new(hash[attribute + '(1i)'].to_i, hash[attribute + '(2i)'].to_i, hash[attribute + '(3i)'].to_i) rescue nil
    end
    hash
  end
  private :process_dates

end
{'fraction_non_alphanumeric': 0.11560347409404013, 'fraction_numerical': 0.002994908655286014, 'mean_word_length': 3.854651162790698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '3305096', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1019, 'n_words': 225}