<commit_before>class WatchlistsController < ApplicationController
  before_filter :authenticate_user!

  def update
    @anime = Anime.find(params["watchlist"]["anime_id"])
    @watchlist = Watchlist.find_or_create_by_anime_id_and_user_id(@anime.id, current_user.id)

    # Update status.
    @watchlist.status = params["watchlist"]["status"]
    
    # Update rating.
    @watchlist.rating = params["watchlist"]["rating"]
    @watchlist.rating = [[@watchlist.rating, -2].max, 2].min
    
    # Update episodes watched.
    episode_count = [0, params["watchlist"]["episodes_watched"].to_i].max
    if episode_count
      @anime.episodes.order(:season_number, :number).limit(episode_count).each do |episode|
        @watchlist.episodes << episode unless @watchlist.episodes.exists?(id: episode.id)
        @watchlist.last_watched = Time.now
        current_user.update_life_spent_on_anime(episode.length)
      end<commit_msg>Actually fix #42.<commit_after>class WatchlistsController < ApplicationController
  before_filter :authenticate_user!

  def update
    @anime = Anime.find(params["watchlist"]["anime_id"])
    @watchlist = Watchlist.find_or_create_by_anime_id_and_user_id(@anime.id, current_user.id)

    # Update status.
    @watchlist.status = params["watchlist"]["status"]
    
    # Update rating.
    @watchlist.rating = params["watchlist"]["rating"]
    @watchlist.rating = [[@watchlist.rating, -2].max, 2].min if @watchlist.rating
    
    # Update episodes watched.
    episode_count = [0, params["watchlist"]["episodes_watched"].to_i].max
    if episode_count
      @anime.episodes.order(:season_number, :number).limit(episode_count).each do |episode|
        @watchlist.episodes << episode unless @watchlist.episodes.exists?(id: episode.id)
        @watchlist.last_watched = Time.now
        current_user.update_life_spent_on_anime(episode.length)
      end
{'fraction_non_alphanumeric': 0.128, 'fraction_numerical': 0.004266666666666667, 'mean_word_length': 4.225626740947075, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '6331662', 'n_tokens_mistral': 622, 'n_tokens_neox': 625, 'n_words': 93}