<commit_before># Report the stock levels of:
#   - all variants in the order
#   - all requested variant ids
require 'open_food_network/scope_variant_to_hub'

class VariantsStockLevels
  def call(order, requested_variant_ids)
    variant_stock_levels = variant_stock_levels(order.line_items)

    order_variant_ids = variant_stock_levels.keys
    missing_variant_ids = requested_variant_ids - order_variant_ids
    missing_variant_ids.each do |variant_id|
      variant = scoped_variant(order.distributor, Spree::Variant.find(variant_id))
      variant_stock_levels[variant_id] = { quantity: 0, max_quantity: 0, on_hand: variant.on_hand, on_demand: variant.on_demand }
    end
<commit_msg>Load variants in cart in one query<commit_after># Report the stock levels of:
#   - all variants in the order
#   - all requested variant ids
require 'open_food_network/scope_variant_to_hub'

class VariantsStockLevels
  def call(order, requested_variant_ids)
    variant_stock_levels = variant_stock_levels(order.line_items)

    order_variant_ids = variant_stock_levels.keys
    missing_variants = Spree::Variant.where(id: (requested_variant_ids - order_variant_ids))

    missing_variants.each do |missing_variant|
      variant = scoped_variant(order.distributor, missing_variant)
      variant_stock_levels[variant.id] =
        { quantity: 0, max_quantity: 0, on_hand: variant.on_hand, on_demand: variant.on_demand }
    end

{'fraction_non_alphanumeric': 0.07329105003523609, 'fraction_numerical': 0.0028188865398167725, 'mean_word_length': 5.068376068376068, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5756322', 'n_tokens_mistral': 466, 'n_tokens_neox': 435, 'n_words': 97}