mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Improve effiency of OrderCycle.earliest_closing_times
This commit is contained in:
@@ -154,9 +154,8 @@ class OrderCycle < ApplicationRecord
|
||||
joins(:order_cycle).
|
||||
merge(OrderCycle.active).
|
||||
group('exchanges.receiver_id').
|
||||
select("exchanges.receiver_id AS receiver_id,
|
||||
MIN(order_cycles.orders_close_at) AS earliest_close_at").
|
||||
map { |ex| [ex.receiver_id, ex.earliest_close_at.to_time] }
|
||||
pluck(Arel.sql("exchanges.receiver_id AS receiver_id"),
|
||||
Arel.sql("MIN(order_cycles.orders_close_at) AS earliest_close_at"))
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ module Api
|
||||
attributes :orders_close_at, :active
|
||||
|
||||
def orders_close_at
|
||||
options[:data].earliest_closing_times[object.id]
|
||||
options[:data].earliest_closing_times[object.id]&.to_time
|
||||
end
|
||||
|
||||
def active
|
||||
|
||||
Reference in New Issue
Block a user