<commit_before>require 'open_food_network/enterprise_issue_validator'

class Api::Admin::ForOrderCycle::EnterpriseSerializer < ActiveModel::Serializer
  attributes :id, :name, :managed,
             :issues_summary_supplier, :issues_summary_distributor,
             :is_primary_producer, :is_distributor, :sells

  def issues_summary_supplier
    issues =
      OpenFoodNetwork::EnterpriseIssueValidator.
        new(object).
        issues_summary(confirmation_only: true)

    if issues.nil? && products.empty?
      issues = "no products in inventory"
    end
    issues
  end

  def issues_summary_distributor
    OpenFoodNetwork::EnterpriseIssueValidator.new(object).issues_summary
  end

  def managed
    Enterprise.managed_by(options[:spree_current_user]).include? object
  end

  private

  def products_scope
    products_relation = object.supplied_products
    if order_cycle.prefers_product_selection_from_coordinator_inventory_only?
      products_relation = products_relation.
        visible_for(order_cycle.coordinator).
        select('DISTINCT spree_products.*')
    end
    products_relation.order(:name)
  end

  def products
    @products ||= products_scope
  end

  def order_cycle
    options[:order_cycle]
  end
end<commit_msg>Remove unnecessary order statement, the relation will only be used for counting products<commit_after>require 'open_food_network/enterprise_issue_validator'

class Api::Admin::ForOrderCycle::EnterpriseSerializer < ActiveModel::Serializer
  attributes :id, :name, :managed,
             :issues_summary_supplier, :issues_summary_distributor,
             :is_primary_producer, :is_distributor, :sells

  def issues_summary_supplier
    issues =
      OpenFoodNetwork::EnterpriseIssueValidator.
        new(object).
        issues_summary(confirmation_only: true)

    if issues.nil? && products.empty?
      issues = "no products in inventory"
    end
    issues
  end

  def issues_summary_distributor
    OpenFoodNetwork::EnterpriseIssueValidator.new(object).issues_summary
  end

  def managed
    Enterprise.managed_by(options[:spree_current_user]).include? object
  end

  private

  def products_scope
    products_relation = object.supplied_products
    if order_cycle.prefers_product_selection_from_coordinator_inventory_only?
      products_relation = products_relation.
        visible_for(order_cycle.coordinator).
        select('DISTINCT spree_products.*')
    end
    products_relation
  end

  def products
    @products ||= products_scope
  end

  def order_cycle
    options[:order_cycle]
  end
end
{'fraction_non_alphanumeric': 0.06897895557287607, 'fraction_numerical': 0.0, 'mean_word_length': 4.033333333333333, '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': '418008', 'n_tokens_mistral': 751, 'n_tokens_neox': 724, 'n_words': 143}