Skip to content

Commit

Permalink
Enhance performance when filter Destinations by rateplan id
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanov-Anton committed Sep 23, 2024
1 parent 39cfde9 commit 6ab7235
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/admin/routing/destinations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
acts_as_import resource_class: Importing::Destination,
skip_columns: [:routing_tag_ids]

scope :low_quality
scope :time_valid
scope :low_quality, show_count: false
scope :time_valid, show_count: false

filter :id
filter :uuid_equals, label: 'UUID'
filter :enabled, as: :select, collection: [['Yes', true], ['No', false]]
filter :prefix
filter :routing_for_contains, as: :string, input_html: { class: 'search_filter_string' }
filter :rate_group, input_html: { class: 'chosen' }
filter :rate_group_rateplans_id_eq, as: :select, input_html: { class: 'chosen' }, label: 'Rateplan', collection: -> { Routing::Rateplan.all }
filter :rateplan_id_filter, as: :select, input_html: { class: 'chosen' }, label: 'Rateplan', collection: -> { Routing::Rateplan.all }
filter :reject_calls, as: :select, collection: [['Yes', true], ['No', false]]
filter :initial_rate
filter :next_rate
Expand Down
24 changes: 24 additions & 0 deletions app/models/class4/rate_plan_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: class4.rate_plan_groups
#
# id :integer(4) not null, primary key
# rate_group_id :integer(4) not null
# rateplan_id :integer(4) not null
#
# Indexes
#
# rate_plan_groups_rateplan_id_rate_group_id_idx (rateplan_id,rate_group_id) UNIQUE
#
# Foreign Keys
#
# rate_plan_groups_rate_group_id_fkey (rate_group_id => rate_groups.id)
# rate_plan_groups_rateplan_id_fkey (rateplan_id => rateplans.id)
#
module Class4
class RatePlanGroup < ApplicationRecord
self.table_name = 'class4.rate_plan_groups'
end
end
5 changes: 5 additions & 0 deletions app/models/routing/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Routing::Destination < ApplicationRecord

scope :low_quality, -> { where quality_alarm: true }
scope :time_valid, -> { where('valid_till >= :time AND valid_from < :time', time: Time.now) }
scope :rateplan_id_filter, ->(value) do
rate_group_ids = Class4::RatePlanGroup.where(rateplan_id: value).pluck(:rate_group_id)
where('rate_group_id IN (?)', rate_group_ids)
end

scope :where_customer, lambda { |id|
joins(:rate_group).joins(:rateplans).joins(:customers_auths).where(CustomersAuth.table_name => { customer_id: id })
Expand Down Expand Up @@ -171,6 +175,7 @@ def self.ransackable_scopes(_auth_object = nil)
routing_tag_ids_covers
tagged
routing_tag_ids_count_equals
rateplan_id_filter
]
end
end

0 comments on commit 6ab7235

Please sign in to comment.