<commit_before>class Api::PostsController < Api::ApplicationController
  def index
    scope = current_site.posts
    scope = scope.joins(:category).merge(Category.where(slug: params[:filter][:category_slug])) if params.dig(:filter, :category_slug)
    scope = scope.where(serial_id: params[:filter][:serial_id])                                 if params.dig(:filter, :serial_id)

    posts = scope.published.order_by_recent.page(params.dig(:page, :number)).per(params.dig(:page, :size))
    render json: posts, include: "category", meta: pagination_meta(posts)
  end

  def show
    post = current_site.posts.published.find_by!(public_id: params[:public_id])

    render json: post, include: "related_posts.category, category, serial"
  end
end<commit_msg>Use categorized scope<commit_after>class Api::PostsController < Api::ApplicationController
  def index
    scope = current_site.posts
    scope = scope.categorized(Category.find_by!(slug: params[:filter][:category_slug])) if params.dig(:filter, :category_slug)
    scope = scope.where(serial_id: params[:filter][:serial_id]) if params.dig(:filter, :serial_id)

    posts = scope.published.order_by_recent.page(params.dig(:page, :number)).per(params.dig(:page, :size))
    render json: posts, include: "category", meta: pagination_meta(posts)
  end

  def show
    post = current_site.posts.published.find_by!(public_id: params[:public_id])

    render json: post, include: "related_posts.category, category, serial"
  end
end
{'fraction_non_alphanumeric': 0.1329284750337382, 'fraction_numerical': 0.0, 'mean_word_length': 5.028455284552845, 'pattern_counts': {'":': 0, '<': 5, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5614587', 'n_tokens_mistral': 453, 'n_tokens_neox': 452, 'n_words': 91}