<commit_before>module ShopHelper
  def order_cycles_name_and_pickup_times(order_cycles)
    order_cycles.map do |oc|
      [
        pickup_time(oc),
        oc.id
      ]
    end
  end

  def oc_select_options
    @order_cycles.map { |oc| { time: pickup_time(oc), id: oc.id } }
  end

  def require_customer?
    current_distributor.require_login? && !user_is_related_to_distributor?
  end

  def user_is_related_to_distributor?
    spree_current_user.present? && (
      spree_current_user.admin? ||
      spree_current_user.enterprises.include?(current_distributor) ||
      spree_current_user.customer_of(current_distributor)
    )
  end

  def shop_tabs
    [
      { name: 'home', title: t(:shopping_tabs_home), show: show_home_tab? },
      { name: 'shop', title: t(:shopping_tabs_shop), show: !require_customer? },
      { name: 'about', title: t(:shopping_tabs_about), show: true },
      { name: 'producers', title: t(:label_producers), show: true },
      { name: 'contact', title: t(:shopping_tabs_contact), show: true },
      { name: 'groups', title: t(:label_groups), show: current_distributor.groups.any? },
    ].select{ |tab| tab[:show] }
  end

  def shop_tab_names
    shop_tabs.map { |tab| tab[:name] }
  end

  def show_home_tab?
    require_customer? || current_distributor.preferred_shopfront_message.present?
  end

  def shopfront_closed_message?
    no_open_order_cycles? && current_distributor.preferred_shopfront_closed_message.present?
  end

  def no_open_order_cycles?
    @order_cycles && @order_cycles.empty?
  end
end
<commit_msg>Memoize helper methods that are called several times in the views<commit_after>module ShopHelper
  def order_cycles_name_and_pickup_times(order_cycles)
    order_cycles.map do |oc|
      [
        pickup_time(oc),
        oc.id
      ]
    end
  end

  def oc_select_options
    @order_cycles.map { |oc| { time: pickup_time(oc), id: oc.id } }
  end

  def require_customer?
    @require_customer ||= current_distributor.require_login? && !user_is_related_to_distributor?
  end

  def user_is_related_to_distributor?
    spree_current_user.present? && (
      spree_current_user.admin? ||
      spree_current_user.enterprises.include?(current_distributor) ||
      spree_current_user.customer_of(current_distributor)
    )
  end

  def shop_tabs
    [
      { name: 'home', title: t(:shopping_tabs_home), show: show_home_tab? },
      { name: 'shop', title: t(:shopping_tabs_shop), show: !require_customer? },
      { name: 'about', title: t(:shopping_tabs_about), show: true },
      { name: 'producers', title: t(:label_producers), show: true },
      { name: 'contact', title: t(:shopping_tabs_contact), show: true },
      { name: 'groups', title: t(:label_groups), show: current_distributor.groups.any? },
    ].select{ |tab| tab[:show] }
  end

  def shop_tab_names
    shop_tabs.map { |tab| tab[:name] }
  end

  def show_home_tab?
    require_customer? || current_distributor.preferred_shopfront_message.present?
  end

  def shopfront_closed_message?
    no_open_order_cycles? && current_distributor.preferred_shopfront_closed_message.present?
  end

  def no_open_order_cycles?
    @no_open_order_cycles ||= @order_cycles&.empty?
  end
end

{'fraction_non_alphanumeric': 0.1132545115121344, 'fraction_numerical': 0.0, 'mean_word_length': 3.923430321592649, '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': '4861382', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1100, 'n_words': 203}