Commit 21a483d7 authored by Mark Chao's avatar Mark Chao

Eager load subscription associations

parent c4820da5
...@@ -24,6 +24,8 @@ class GitlabSubscription < ApplicationRecord ...@@ -24,6 +24,8 @@ class GitlabSubscription < ApplicationRecord
with_hosted_plan(Plan::PAID_HOSTED_PLANS) with_hosted_plan(Plan::PAID_HOSTED_PLANS)
end end
scope :preload_for_refresh_seat, -> { preload([{ namespace: :route }, :hosted_plan]) }
DAYS_AFTER_EXPIRATION_BEFORE_REMOVING_FROM_INDEX = 7 DAYS_AFTER_EXPIRATION_BEFORE_REMOVING_FROM_INDEX = 7
# We set a 7 days as the threshold for expiration before removing them from # We set a 7 days as the threshold for expiration before removing them from
......
...@@ -12,7 +12,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab ...@@ -12,7 +12,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.read_only?
return unless ::Gitlab::CurrentSettings.should_check_namespace_plan? return unless ::Gitlab::CurrentSettings.should_check_namespace_plan?
GitlabSubscription.with_a_paid_hosted_plan.find_in_batches(batch_size: 100) do |subscriptions| GitlabSubscription.with_a_paid_hosted_plan.preload_for_refresh_seat.find_in_batches(batch_size: 100) do |subscriptions|
tuples = [] tuples = []
subscriptions.each do |subscription| subscriptions.each do |subscription|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment