summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Rocco <alessio.rocco.lt@gmail.com>2021-01-29 11:46:26 +0100
committerAlessio Rocco <alessio.rocco.lt@gmail.com>2021-01-29 11:52:31 +0100
commit90ea23c6911ff2454f66a90fbd8c377d3aec1a49 (patch)
tree04dffd70459c6a43dc9e2040aed0c362c4cebea3
parent69f0ca038b66d0ca36971405e51c0d3aa916cf19 (diff)
Improve "unfulfilled" scope by adding subquery
"SolidusSubscriptions::Installment#unfulfilled" gets the list of fulfilled installments, loads them ALL into memory, and then performs a WHERE id NOT IN (...) to get the installments that were not fulfilled, this commit simplify the scope using a WHERE clause with a subquery.
-rw-r--r--app/models/solidus_subscriptions/installment.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/app/models/solidus_subscriptions/installment.rb b/app/models/solidus_subscriptions/installment.rb
index 0b5f627..5ea6a06 100644
--- a/app/models/solidus_subscriptions/installment.rb
+++ b/app/models/solidus_subscriptions/installment.rb
@@ -19,8 +19,7 @@ module SolidusSubscriptions
end)
scope :unfulfilled, (lambda do
- fulfilled_ids = fulfilled.pluck(:id)
- where.not(id: fulfilled_ids).distinct
+ where.not(id: Installment.fulfilled).distinct
end)
scope :with_active_subscription, (lambda do