<commit_before>class AdminController < ApplicationController

  layout 'admin'

  before_action :authenticate_user!
  before_action :verify_admin
  before_action :fetch_counts, :only => ['dashboard','tickets','ticket', 'update_ticket', 'topic_search', 'user_profile']
  before_action :pipeline, :only => ['tickets', 'ticket', 'topic_search', 'update_ticket']
  before_action :remote_search, :only => ['tickets', 'ticket', 'topic_search', 'update_ticket']

  def dashboard
    #@users = PgSearch.multisearch(params[:q]).page params[:page]
    @topics = Topic.mine(current_user.id).pending.page params[:page]
  end

  def knowledgebase
    @categories = Category.featured.alpha
    @nonfeatured = Category.where(front_page: false).alpha

    respond_to do |format|
      format.html { render :action => "knowledgebase" }
    end
  end

  def articles
    @category = Category.where(id: params[:category_id]).first
    @docs = @category.docs.ordered.alpha

    respond_to do |format|
      format.html
      format.xml  { render :xml => @category }
    end
  end

  def tickets

    if params[:status].nil?
      @status = "pending"
    else
      @status = params[:status]
    end

    topics_raw = Topic.includes(:user).chronologic
    case @status
    when 'all'
      topics_raw = topics_raw.all
    when 'new'
      topics_raw = topics_raw.unread
    when 'active'
      topics_raw = topics_raw.active
    when 'unread'
      topics_raw = topics_raw.unread.all
    when 'assigned'
      topics_raw = topics_raw.mine(current_user.id)
    when 'pending'
      topics_raw = topics_raw.pending.mine(current_user.id)
    else
      topics_raw = topics_raw.where(current_status: @status)
    end
    @topics = topics_raw.page params[:page]

    @tracker.event(category: "Admin-Nav", action: "Click", label: @status.titleize)

    respond_to do |format|
      format.html
      format.js
    end

  end

  # view ticket
  def ticket
<commit_msg>Avoid N+1 query on user's attachinary avatar retrieval<commit_after>class AdminController < ApplicationController

  layout 'admin'

  before_action :authenticate_user!
  before_action :verify_admin
  before_action :fetch_counts, :only => ['dashboard','tickets','ticket', 'update_ticket', 'topic_search', 'user_profile']
  before_action :pipeline, :only => ['tickets', 'ticket', 'topic_search', 'update_ticket']
  before_action :remote_search, :only => ['tickets', 'ticket', 'topic_search', 'update_ticket']

  def dashboard
    #@users = PgSearch.multisearch(params[:q]).page params[:page]
    @topics = Topic.mine(current_user.id).pending.page params[:page]
  end

  def knowledgebase
    @categories = Category.featured.alpha
    @nonfeatured = Category.where(front_page: false).alpha

    respond_to do |format|
      format.html { render :action => "knowledgebase" }
    end
  end

  def articles
    @category = Category.where(id: params[:category_id]).first
    @docs = @category.docs.ordered.alpha

    respond_to do |format|
      format.html
      format.xml  { render :xml => @category }
    end
  end

  def tickets

    if params[:status].nil?
      @status = "pending"
    else
      @status = params[:status]
    end

    topics_raw = Topic.includes(user: :avatar_files).chronologic
    case @status
    when 'all'
      topics_raw = topics_raw.all
    when 'new'
      topics_raw = topics_raw.unread
    when 'active'
      topics_raw = topics_raw.active
    when 'unread'
      topics_raw = topics_raw.unread.all
    when 'assigned'
      topics_raw = topics_raw.mine(current_user.id)
    when 'pending'
      topics_raw = topics_raw.pending.mine(current_user.id)
    else
      topics_raw = topics_raw.where(current_status: @status)
    end
    @topics = topics_raw.page params[:page]

    @tracker.event(category: "Admin-Nav", action: "Click", label: @status.titleize)

    respond_to do |format|
      format.html
      format.js
    end

  end

  # view ticket
  def ticket

{'fraction_non_alphanumeric': 0.1156289707750953, 'fraction_numerical': 0.00025412960609911054, 'mean_word_length': 3.4274465691788527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '109721', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1248, 'n_words': 278}