<commit_before>class IcalController < ApplicationController
  GABBA_MAPPING = {
    general: "iCal",
    personalized: "iCal-personalized",
    like_welcome_page: "iCal-not-hated"
  }

  before_filter :set_calendar_headers
  before_filter :gabba,
    only: GABBA_MAPPING.keys,
    if: ->{ Rails.env.production? }
  rescue_from ActiveRecord::RecordNotFound, with: :render_empty

  def general
    render_events SingleEvent.where(occurrence: time_range)
  end

  def personalized
    render_events user.single_events.where(occurrence: time_range)
  end

  def like_welcome_page
    @presets_json = CalendarPreset.presets_for_user(user)
    @single_events = SingleEvent.where(occurrence: time_range).in_categories(@presets_json[:diy])
    @single_events.select! { |single_event| single_event.is_for_user? user }
    render_events @single_events
  end

  def for_single_event
    render_event SingleEvent.find(params[:id])
  end

  def for_event
    render_events Event.find(params[:id]).single_events
  end

  def for_tag
    render_events SingleEvent.only_tagged_with(params[:id])
  end

  private

  def set_calendar_headers
    response.headers["Content-Type"] = "text/calendar; charset=UTF-8"<commit_msg>use SingleEvent.recent_to_soon scope in IcalController<commit_after>class IcalController < ApplicationController
  GABBA_MAPPING = {
    general: "iCal",
    personalized: "iCal-personalized",
    like_welcome_page: "iCal-not-hated"
  }

  before_filter :set_calendar_headers
  before_filter :gabba,
    only: GABBA_MAPPING.keys,
    if: ->{ Rails.env.production? }
  rescue_from ActiveRecord::RecordNotFound, with: :render_empty

  def general
    render_events SingleEvent.recent_to_soon(3.months)
  end

  def personalized
    render_events user.single_events.recent_to_soon(3.months)
  end

  def like_welcome_page
    @presets_json = CalendarPreset.presets_for_user(user)
    @single_events = SingleEvent.recent_to_soon(3.months).in_categories(@presets_json[:diy])
    @single_events.select! { |single_event| single_event.is_for_user? user }
    render_events @single_events
  end

  def for_single_event
    render_event SingleEvent.find(params[:id])
  end

  def for_event
    render_events Event.find(params[:id]).single_events
  end

  def for_tag
    render_events SingleEvent.only_tagged_with(params[:id])
  end

  private

  def set_calendar_headers
    response.headers["Content-Type"] = "text/calendar; charset=UTF-8"
{'fraction_non_alphanumeric': 0.08990147783251232, 'fraction_numerical': 0.002052545155993432, 'mean_word_length': 4.747641509433962, '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': '7130042', 'n_tokens_mistral': 845, 'n_tokens_neox': 800, 'n_words': 138}