<commit_before>class Feed
  attr_reader :notifications, :user, :upto

  def self.for_user(user, filters, category = :all, page = 1, per = 25)
    base_query = Notification.where(notified_user: user)
      .eager_load(event: [:originating_user])
      .order('notifications.created_at DESC')
      .page(page)
      .per(per)

    if category.to_s != 'all'
      base_query = base_query.where(type: Notification.types[category.singularize])
    end

    filtered_query = filter(base_query, filters)
    Feed.new(filtered_query, user)
  end

  private
  def self.filter(query, filters)
    Array(filters).inject(query) do |q, (col, val)|
      filter_column_map[col].call(q, val)
    end
  end

  def self.filter_column_map
    unless @filter_column_map
      @filter_column_map = Hash.new(->(q,v) {q})
      @filter_column_map['name'] = ->(q, v) { q.where(Constants::DISPLAY_NAME_QUERY, query: "%#{v}%") }
      @filter_column_map['limit']  = ->(q, v) { q.where('notifications.created_at >= :query', query: Constants::TIMESPAN_MAP[v]) }
    end
    @filter_column_map
  end

  def initialize(notifications, user)
    @user = user
    @notifications = notifications
    @upto = Time.now
  end
end
<commit_msg>allow filtering on unlikable and unseen<commit_after>class Feed
  attr_reader :notifications, :user, :upto

  def self.for_user(user, filters, category = :all, page = 1, per = 25)
    base_query = Notification.where(notified_user: user)
      .eager_load(event: [:originating_user])
      .order('notifications.created_at DESC')
      .page(page)
      .per(per)

    if category.to_s != 'all'
      base_query = base_query.where(type: Notification.types[category.singularize])
    end

    filtered_query = filter(base_query, filters)
    Feed.new(filtered_query, user)
  end

  private
  def self.filter(query, filters)
    Array(filters).inject(query) do |q, (col, val)|
      filter_column_map[col].call(q, val)
    end
  end

  def self.filter_column_map
    unless @filter_column_map
      @filter_column_map = Hash.new(->(q,v) {q})
      @filter_column_map['name'] = ->(q, v) { q.where(Constants::DISPLAY_NAME_QUERY, query: "%#{v}%") }
      @filter_column_map['limit']  = ->(q, v) { q.where('notifications.created_at >= :query', query: Constants::TIMESPAN_MAP[v]) }
      @filter_column_map['unseen']  = ->(q, v) { q.where('notifications.unseen = :query', query: v) }
      @filter_column_map['unlinkable']  = ->(q, v) { q.where('notifications.unlinkable = :query', query: v) }
    end
    @filter_column_map
  end

  def initialize(notifications, user)
    @user = user
    @notifications = notifications
    @upto = Time.now
  end
end

{'fraction_non_alphanumeric': 0.1425339366515837, 'fraction_numerical': 0.0022624434389140274, 'mean_word_length': 3.687279151943463, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '65947', 'n_tokens_mistral': 958, 'n_tokens_neox': 923, 'n_words': 187}