<commit_before>class VideosRepository
  SUBQUERY = <<-SQL
    SELECT DISTINCT ON (origin_id) * FROM episodes
  SQL

  def page(number)
    scope = Episode.select('*').from("(#{SUBQUERY}) AS videos").order('created_at DESC').page(number)

    def scope.count
      Episode.connection.select_value "SELECT COUNT(*) FROM (#{SUBQUERY}) AS videos"
    end

    scope
  end
end<commit_msg>cache videos counter<commit_after>class VideosRepository
  SUBQUERY = <<-SQL
    SELECT DISTINCT ON (origin_id) * FROM episodes
  SQL

  def page(number)
    scope = Episode.select('*').from("(#{SUBQUERY}) AS videos").order('created_at DESC').page(number)

    def scope.count
      Rails.cache.fetch 'VideosRepository#page:count', expires_in: 10.minutes do
        Episode.connection.select_value "SELECT COUNT(*) FROM (#{SUBQUERY}) AS videos"
      end
    end

    scope
  end
end
{'fraction_non_alphanumeric': 0.1258660508083141, 'fraction_numerical': 0.0023094688221709007, 'mean_word_length': 3.7637362637362637, 'pattern_counts': {'":': 0, '<': 7, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2348741', 'n_tokens_mistral': 290, 'n_tokens_neox': 270, 'n_words': 69}