Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSU-124] Improve facility show loading speed #5075

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def facility_product_path(facility, product)
def warning_if_instrument_is_offline_or_partially_available(instrument)
if instrument.offline?
tooltip_icon "fa fa-exclamation-triangle icon-large", t("instruments.offline.note")
elsif instrument.alert
elsif instrument.alert.present?
tooltip_icon "fa fa-exclamation-triangle partially-available-warning icon-large", instrument.alert.note
end
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/concerns/products/scheduling_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def quick_reservation_intervals
end

def offline?
current_offline_reservations.present?
if current_offline_reservations.loaded?
current_offline_reservations.present?
else
current_offline_reservations.exists?
end
end

def offline_category
Expand Down
10 changes: 4 additions & 6 deletions app/models/instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ module Pricing
end
end.freeze

with_options foreign_key: "product_id" do |instrument|
instrument.has_many :admin_reservations
instrument.has_many :instrument_price_policies
instrument.has_many :offline_reservations
instrument.has_many :current_offline_reservations, -> { current }, class_name: "OfflineReservation"
with_options foreign_key: "product_id" do
has_many :admin_reservations
has_many :instrument_price_policies
has_many :offline_reservations
end
has_one :alert, dependent: :destroy, class_name: "InstrumentAlert"

email_list_attribute :cancellation_email_recipients
email_list_attribute :issue_report_recipients
Expand Down
22 changes: 13 additions & 9 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ class Product < ApplicationRecord
has_one :product_display_group_product
has_one :product_display_group, through: :product_display_group_product

# Instrument specifc
has_one(
:alert,
dependent: :destroy,
class_name: "InstrumentAlert",
foreign_key: :instrument_id,
inverse_of: :instrument
)
has_many :current_offline_reservations, -> { current }, class_name: "OfflineReservation"

before_save :start_time_disabled_daily_booking_only
after_create :create_default_price_group_products
after_create :create_skip_review_price_policies, if: :skip_review_mode?
after_create :create_nonbillable_price_policy, if: :nonbillable_mode?
before_save :start_time_disabled_daily_booking_only

email_list_attribute :training_request_contacts

Expand Down Expand Up @@ -70,11 +80,9 @@ def self.billing_modes
scope :mergeable_into_order, -> { not_archived.where(type: mergeable_types) }
scope :cross_core_available, -> { where(cross_core_ordering_available: true) }
scope :in_active_facility, -> { joins(:facility).where(facilities: { is_active: true }) }
scope :of_type, ->(type) { where(type: type) }
scope :of_type, ->(type) { where(type:) }
scope :with_schedule, -> { where.not(schedule_id: nil) }
scope :without_display_group, -> {
left_outer_joins(:product_display_group_product).where(product_display_group_products: { id: nil })
}
scope :without_display_group, -> { where.missing(:product_display_group_product) }

# All product types. This cannot be a cattr_accessor because the block is evaluated
# at definition time (not lazily as I expected) and this causes a circular dependency
Expand Down Expand Up @@ -332,10 +340,6 @@ def is_accessible_to_user?(user)
!(is_archived? || (is_hidden? && !is_operator))
end

def alert
nil
end

def duration_pricing_mode?
false
end
Expand Down
5 changes: 4 additions & 1 deletion app/models/product_display_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def to_s

def self.fake_groups_by_type(products)
Product.orderable_types.map do |type|
Fake.new(name: type.constantize.model_name.human(count: :many), products: products.where(type: type))
Fake.new(
name: type.constantize.model_name.human(count: :many),
products: products.where(type:)
)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/facilities/_product_display_group.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- collection = product_display_group.products.merge(@product_scope)
- collection = product_display_group.products.merge(@product_scope).includes(:alert, :current_offline_reservations)
- if collection.present?
.product_list{ class: classes }
%h3= product_display_group
Expand Down