From 90ea23c6911ff2454f66a90fbd8c377d3aec1a49 Mon Sep 17 00:00:00 2001 From: Alessio Rocco Date: Fri, 29 Jan 2021 11:46:26 +0100 Subject: 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. --- app/models/solidus_subscriptions/installment.rb | 3 +-- 1 file changed, 1 insertion(+), 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 -- cgit v1.2.3