<commit_before># frozen_string_literal: true
# == Schema Information
#
# Table name: works
#
#  id                :integer          not null, primary key
#  season_id         :integer
#  sc_tid            :integer
#  title             :string(510)      not null
#  media             :integer          not null
#  official_site_url :string(510)      default(""), not null
#  wikipedia_url     :string(510)      default(""), not null
#  episodes_count    :integer          default(0), not null
#  watchers_count    :integer          default(0), not null
#  released_at       :date
#  created_at        :datetime
#  updated_at        :datetime
#  twitter_username  :string(510)
#  twitter_hashtag   :string(510)
#  released_at_about :string
#  aasm_state        :string           default("published"), not null
#  number_format_id  :integer
#  title_kana        :string           default(""), not null
#
# Indexes
#
#  index_works_on_aasm_state        (aasm_state)
#  index_works_on_number_format_id  (number_format_id)
#  works_sc_tid_key                 (sc_tid) UNIQUE
#  works_season_id_idx              (season_id)
#

class WorksController < ApplicationController
  include ApplicationHelper

  before_action :authenticate_user!, only: %i(switch)

  def index
    redirect_to season_works_path(ENV["ANNICT_CURRENT_SEASON"])
  end

  def popular(page: nil)
    @works = Work.
      published.
      includes(:work_image).
      order(watchers_count: :desc, id: :desc).
      page(page).
      per(display_works_count)
    @pvs_data = Work.pvs_data(@works)
    @casts_data = Work.casts_data(@works)
    @staffs_data = Work.staffs_data(@works, major: true)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_list",
      user: current_user,
      works: @works,
      with_friends: true
  end

  def newest(page: nil)
    @works = Work.
      published.
      includes(:work_image).
      order(id: :desc).
      page(page).
      per(display_works_count)
    @pvs_data = Work.pvs_data(@works)
    @casts_data = Work.casts_data(@works)
    @staffs_data = Work.staffs_data(@works, major: true)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_list",
      user: current_user,
      works: @works,
      with_friends: true
  end

  def season(slug, page: nil)
    @works = Work.
      published.
      by_season(slug).
      includes(:work_image).
      order(watchers_count: :desc, id: :desc).
      page(page).
      per(display_works_count)
    @pvs_data = Work.pvs_data(@works)
    @casts_data = Work.casts_data(@works)
    @staffs_data = Work.staffs_data(@works, major: true)
    @program_details_data = Work.program_details_data(@works, only_video_service: true)
    @seasons = Season.list(sort: :desc, include_all: true)
    @season = Season.find_by_slug(slug)
    @prev_season = @season.sibling_season(:prev)
    @next_season = @season.sibling_season(:next)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_list",
      user: current_user,
      works: @works,
      with_friends: true
  end

  def show
    @work = Work.published.find(params[:id])
    @episodes = @work.episodes.published.order(:sort_number)
    @casts = @work.
      casts.
      published.
      order(:sort_number)
    @staffs = @work.
      staffs.
      published.
      order(:sort_number)
    @series_list = @work.series_list.published.where("series_works_count > ?", 1)
    @reviews = @work.reviews.published.order(created_at: :desc)
    @items = @work.items.published.order(created_at: :desc).limit(10)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_detail",
      user: current_user,
      work: @work
  end

  def switch(to)
    redirect = redirect_back fallback_location: works_path

    return redirect unless to.in?(Setting.display_option_work_list.values)

    current_user.setting.update_column(:display_option_work_list, to)
    redirect
  end
end
<commit_msg>Fix a poor bug 😇<commit_after># frozen_string_literal: true
# == Schema Information
#
# Table name: works
#
#  id                :integer          not null, primary key
#  season_id         :integer
#  sc_tid            :integer
#  title             :string(510)      not null
#  media             :integer          not null
#  official_site_url :string(510)      default(""), not null
#  wikipedia_url     :string(510)      default(""), not null
#  episodes_count    :integer          default(0), not null
#  watchers_count    :integer          default(0), not null
#  released_at       :date
#  created_at        :datetime
#  updated_at        :datetime
#  twitter_username  :string(510)
#  twitter_hashtag   :string(510)
#  released_at_about :string
#  aasm_state        :string           default("published"), not null
#  number_format_id  :integer
#  title_kana        :string           default(""), not null
#
# Indexes
#
#  index_works_on_aasm_state        (aasm_state)
#  index_works_on_number_format_id  (number_format_id)
#  works_sc_tid_key                 (sc_tid) UNIQUE
#  works_season_id_idx              (season_id)
#

class WorksController < ApplicationController
  include ApplicationHelper

  before_action :authenticate_user!, only: %i(switch)

  def index
    redirect_to season_works_path(ENV["ANNICT_CURRENT_SEASON"])
  end

  def popular(page: nil)
    @works = Work.
      published.
      includes(:work_image).
      order(watchers_count: :desc, id: :desc).
      page(page).
      per(display_works_count)
    @pvs_data = Work.pvs_data(@works)
    @casts_data = Work.casts_data(@works)
    @staffs_data = Work.staffs_data(@works, major: true)
    @program_details_data = Work.program_details_data(@works, only_video_service: true)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_list",
      user: current_user,
      works: @works,
      with_friends: true
  end

  def newest(page: nil)
    @works = Work.
      published.
      includes(:work_image).
      order(id: :desc).
      page(page).
      per(display_works_count)
    @pvs_data = Work.pvs_data(@works)
    @casts_data = Work.casts_data(@works)
    @staffs_data = Work.staffs_data(@works, major: true)
    @program_details_data = Work.program_details_data(@works, only_video_service: true)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_list",
      user: current_user,
      works: @works,
      with_friends: true
  end

  def season(slug, page: nil)
    @works = Work.
      published.
      by_season(slug).
      includes(:work_image).
      order(watchers_count: :desc, id: :desc).
      page(page).
      per(display_works_count)
    @pvs_data = Work.pvs_data(@works)
    @casts_data = Work.casts_data(@works)
    @staffs_data = Work.staffs_data(@works, major: true)
    @program_details_data = Work.program_details_data(@works, only_video_service: true)
    @seasons = Season.list(sort: :desc, include_all: true)
    @season = Season.find_by_slug(slug)
    @prev_season = @season.sibling_season(:prev)
    @next_season = @season.sibling_season(:next)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_list",
      user: current_user,
      works: @works,
      with_friends: true
  end

  def show
    @work = Work.published.find(params[:id])
    @episodes = @work.episodes.published.order(:sort_number)
    @casts = @work.
      casts.
      published.
      order(:sort_number)
    @staffs = @work.
      staffs.
      published.
      order(:sort_number)
    @series_list = @work.series_list.published.where("series_works_count > ?", 1)
    @reviews = @work.reviews.published.order(created_at: :desc)
    @items = @work.items.published.order(created_at: :desc).limit(10)

    return unless user_signed_in?

    gon.pageObject = render_jb "works/_detail",
      user: current_user,
      work: @work
  end

  def switch(to)
    redirect = redirect_back fallback_location: works_path

    return redirect unless to.in?(Setting.display_option_work_list.values)

    current_user.setting.update_column(:display_option_work_list, to)
    redirect
  end
end

{'fraction_non_alphanumeric': 0.1064671695313466, 'fraction_numerical': 0.004946209966613083, 'mean_word_length': 2.928120446818844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4650641', 'n_tokens_mistral': 2741, 'n_tokens_neox': 2645, 'n_words': 536}