<commit_before>class ReviewsController < ApplicationController
  def full_index
    # TODO
  end

  def index
    @anime = Anime.find(params[:anime_id])
    if user_signed_in?
      @watchlist = current_user.watchlists.where(anime_id: @anime).first
    end
    @reviews = Review.includes(:user).find_with_reputation(:votes, :all, {:conditions => ["anime_id = ?", @anime.id], :order => 'votes DESC'})
    @user_evaluations = Hash.new(false)
    if user_signed_in?
      @reviews.map {|x| x.evaluations.where(source_id: current_user.id).first }.each do |evaluation|
        @user_evaluations[evaluation.target_id] = evaluation if evaluation
      end
    end
  end

  def show
    @anime = Anime.find(params[:anime_id])
    @review = Review.find(params[:id])
    @recent_reviews = Review.order('created_at DESC').limit(10).select {|x| x.anime.sfw? }
    if user_signed_in?
      @evaluation = @review.evaluations.where(source_id: current_user.id).first
    end
  end
  
  def vote
    authenticate_user!
    value = params[:type] == "up" ? 1 : 0
    @review = Review.find(params[:id])
    @review.add_or_update_evaluation(:votes, value, current_user)
    TrendingReviews.vote @review.id if value == 1
    redirect_to :back
  end
  
  def new
    authenticate_user!
    @anime = Anime.find(params[:anime_id])
    if Review.exists?(user_id: current_user, anime_id: @anime)
      @review = Review.find_by_user_id_and_anime_id(current_user.id, @anime.id)
      redirect_to edit_anime_review_path(@anime, @review)
    else
      @review = Review.new(user: current_user)
    end
  end

  def create
    authenticate_user!
    
    @anime = Anime.find(params[:anime_id])<commit_msg>Review voting bugfix.<commit_after>
class ReviewsController < ApplicationController
  def full_index
    # TODO
  end

  def index
    @anime = Anime.find(params[:anime_id])
    if user_signed_in?
      @watchlist = current_user.watchlists.where(anime_id: @anime).first
    end
    @reviews = Review.includes(:user).find_with_reputation(:votes, :all, {:conditions => ["anime_id = ?", @anime.id], :order => 'votes DESC'})
    @user_evaluations = Hash.new(false)
    if user_signed_in?
      @reviews.map {|x| x.evaluations.where(source_id: current_user.id).first }.each do |evaluation|
        @user_evaluations[evaluation.target_id] = evaluation if evaluation
      end
    end
  end

  def show
    @anime = Anime.find(params[:anime_id])
    @review = Review.find(params[:id])
    @recent_reviews = Review.order('created_at DESC').limit(10).select {|x| x.anime.sfw? }
    if user_signed_in?
      @evaluation = @review.evaluations.where(source_id: current_user.id).first
    end
  end
  
  def vote
    authenticate_user!
    value = params[:type] == "up" ? 1 : 0
    @review = Review.find(params[:id])
    @review.add_or_update_evaluation(:votes, value, current_user)
    TrendingReview.vote @review.id if value == 1
    redirect_to :back
  end
  
  def new
    authenticate_user!
    @anime = Anime.find(params[:anime_id])
    if Review.exists?(user_id: current_user, anime_id: @anime)
      @review = Review.find_by_user_id_and_anime_id(current_user.id, @anime.id)
      redirect_to edit_anime_review_path(@anime, @review)
    else
      @review = Review.new(user: current_user)
    end
  end

  def create
    authenticate_user!
    
    @anime = Anime.find(params[:anime_id])
{'fraction_non_alphanumeric': 0.12313655336911151, 'fraction_numerical': 0.0029815146094215863, 'mean_word_length': 3.6021947873799727, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5509490', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1189, 'n_words': 222}