<commit_before>require 'wilson_score'

class AnimeController < ApplicationController
  include EpisodesHelper

  caches_action :show, if: lambda { not user_signed_in? }, expires_in: 1.hour
  
  def random
    anime = Anime.where("age_rating <> 'R18+'").where(show_type: ["TV", "OVA", "ONA", "Movie"]).order("RANDOM()").limit(1)[0]
    redirect_to anime
  end
  
  def show
    @anime = Anime.find(params[:id])
    # Redirect the user to the canonical URL if they got here from an old or
    # numeric ID.
    if request.path != anime_path(@anime)
      return redirect_to @anime, :status => :moved_permanently
    end
    
    @genres = @anime.genres
    @producers = @anime.producers
    @quotes = Quote.includes(:user).find_with_reputation(:votes, :all, {:conditions => ["anime_id = ?", @anime.id], :order => "votes DESC", :limit => 4})
    
    @castings = Casting.where(anime_id: @anime.id, featured: true).sort_by {|x| x.order || 1000 }
    @languages = @castings.map {|x| x.role }.sort
    ["Japanese", "English"].reverse.each do |l|
      @languages.unshift l if @languages.include? l
    end
    @languages = @languages.uniq

    @gallery = @anime.gallery_images.limit(6)
<commit_msg>Improve server load time of the show anime pages.<commit_after>require 'wilson_score'

class AnimeController < ApplicationController
  include EpisodesHelper

  caches_action :show, if: lambda { not user_signed_in? }, expires_in: 1.hour
  
  def random
    anime = Anime.where("age_rating <> 'R18+'").where(show_type: ["TV", "OVA", "ONA", "Movie"]).order("RANDOM()").limit(1)[0]
    redirect_to anime
  end
  
  def show
    @anime = Anime.find(params[:id])
    # Redirect the user to the canonical URL if they got here from an old or
    # numeric ID.
    if request.path != anime_path(@anime)
      return redirect_to @anime, :status => :moved_permanently
    end
    
    @genres = @anime.genres
    @producers = @anime.producers
    @quotes = Quote.includes(:user).find_with_reputation(:votes, :all, {:conditions => ["anime_id = ?", @anime.id], :order => "votes DESC", :limit => 4})
    
    @castings = Casting.where(anime_id: @anime.id, featured: true).includes(:person, :character).sort_by {|x| x.order || 1000 }
    @languages = @castings.map {|x| x.role }.sort
    ["Japanese", "English"].reverse.each do |l|
      @languages.unshift l if @languages.include? l
    end
    @languages = @languages.uniq

    @gallery = @anime.gallery_images.limit(6)

{'fraction_non_alphanumeric': 0.14816326530612245, 'fraction_numerical': 0.008979591836734694, 'mean_word_length': 3.6954022988505746, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3499936', 'n_tokens_mistral': 898, 'n_tokens_neox': 854, 'n_words': 207}