Skip to content

Commit

Permalink
Merge pull request #1559 from yeti-switch/1556-destination-filter-by-…
Browse files Browse the repository at this point in the history
…rateplan-improvement

1556, Enhance performance when filter Destinations by rateplan id
  • Loading branch information
dmitry-sinina authored Sep 24, 2024
2 parents 9234b3e + 556894e commit c5fb915
Show file tree
Hide file tree
Showing 4 changed files with 53 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
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, lambda { |value|
rate_group_ids = Routing::RatePlanGroup.where(rateplan_id: value).pluck(:rate_group_id)
where('rate_group_id IN (?)', rate_group_ids)
}

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
24 changes: 24 additions & 0 deletions app/models/routing/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 Routing
class RatePlanGroup < ApplicationRecord
self.table_name = 'class4.rate_plan_groups'
end
end
21 changes: 21 additions & 0 deletions spec/features/routing/destinations/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,25 @@
end
end
end

context 'filter by Rateplan', js: false do
subject { click_button :Filter }

let!(:rate_group) { FactoryBot.create(:rate_group) }
let!(:rate_group_second) { FactoryBot.create(:rate_group) }
let!(:rateplan) { FactoryBot.create(:rateplan, rate_groups: [rate_group, rate_group_second]) }
let!(:record) { FactoryBot.create(:destination, rate_group:) }

before do
visit destinations_path
select rateplan.name, from: 'Rateplan'
end

it 'should render filtered records only' do
subject

expect(page).to have_table_row count: 1
expect(page).to have_table_cell column: 'Id', exact_text: record.id.to_s
end
end
end

0 comments on commit c5fb915

Please sign in to comment.