<commit_before>class StorySerializer < ActiveModel::Serializer
  embed :ids, include: true

  attributes :id, :type, :created_at, :comment

  has_one :user, embed_key: :name
  has_one :media, polymorphic: true, embed_key: :slug
  has_one :poster, embed_key: :name, root: :users
  has_many :followed_users, embed_key: :name, root: :users
  has_many :substories

  def type
    object.story_type
  end

  def poster
    object.target
  end
  def include_poster?
    object.story_type == "comment"
  end

  def comment
    first_substory = object.substories.first
    # FIXME This logic doesn't belong in a serializer. Move it to the substory
    # before_save hook.
    if first_substory
      formatted_comment = MessageFormatter.format_message first_substory.data["comment"]
      first_substory.data["formatted_comment"] = formatted_comment
      first_substory.save
    first_substory.data["formatted_comment"]
    end
      end
  def include_comment?
    object.story_type == "comment"
  end

  def media
    object.target
  end
  def include_media?<commit_msg>Speed up story serializer by ∞%<commit_after>class StorySerializer < ActiveModel::Serializer
  embed :ids, include: true

  attributes :id, :type, :created_at, :comment

  has_one :user, embed_key: :name
  has_one :media, polymorphic: true, embed_key: :slug
  has_one :poster, embed_key: :name, root: :users
  has_many :followed_users, embed_key: :name, root: :users
  has_many :substories

  def type
    object.story_type
  end

  def poster
    object.target
  end
  def include_poster?
    object.story_type == "comment"
  end

  def comment
    first_substory = object.substories.first
    # FIXME This logic doesn't belong in a serializer. Move it to the substory
    # before_save hook.
    if first_substory && !first_substory.data["formatted_comment"]
      formatted_comment = MessageFormatter.format_message first_substory.data["comment"]
      first_substory.data["formatted_comment"] = formatted_comment
      first_substory.save!
    end
    first_substory.data["formatted_comment"]
  end
  def include_comment?
    object.story_type == "comment"
  end

  def media
    object.target
  end
  def include_media?
{'fraction_non_alphanumeric': 0.08180987202925045, 'fraction_numerical': 0.0, 'mean_word_length': 3.8536585365853657, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6420002', 'n_tokens_mistral': 712, 'n_tokens_neox': 693, 'n_words': 185}