<commit_before># frozen_string_literal: true

class HashtagQueryService < BaseService
  def call(tag, params, account = nil, local = false)
    tags = tags_for(Array(tag.name) | Array(params[:any])).pluck(:id)
    all  = tags_for(params[:all])
    none = tags_for(params[:none])

    Status.distinct
          .as_tag_timeline(tags, account, local)
          .tagged_with_all(all)
          .tagged_with_none(none)
  end

  private

  def tags_for(names)
    Tag.matching_name(names) if names.presence
  end
end<commit_msg>Fix hashtag timeline REST API accepting too many hashtags (#12091)<commit_after># frozen_string_literal: true

class HashtagQueryService < BaseService
  LIMIT_PER_MODE = 4

  def call(tag, params, account = nil, local = false)
    tags = tags_for(Array(tag.name) | Array(params[:any])).pluck(:id)
    all  = tags_for(params[:all])
    none = tags_for(params[:none])

    Status.distinct
          .as_tag_timeline(tags, account, local)
          .tagged_with_all(all)
          .tagged_with_none(none)
  end

  private

  def tags_for(names)
    Tag.matching_name(Array(names).take(LIMIT_PER_MODE)) if names.present?
  end
end
{'fraction_non_alphanumeric': 0.1114012184508268, 'fraction_numerical': 0.005221932114882507, 'mean_word_length': 3.693877551020408, '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': '4212287', 'n_tokens_mistral': 406, 'n_tokens_neox': 384, 'n_words': 80}