From 704944b60c131e6289ff15cd1c2afe6cff989cf9 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 31 Dec 2019 09:27:18 +1100 Subject: [PATCH] feat(matrix): optimise the query that determines the integrations --- lib/pact_broker/matrix/query_builder.rb | 2 +- lib/pact_broker/matrix/quick_row.rb | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/pact_broker/matrix/query_builder.rb b/lib/pact_broker/matrix/query_builder.rb index 7bba20f88..aa714a428 100644 --- a/lib/pact_broker/matrix/query_builder.rb +++ b/lib/pact_broker/matrix/query_builder.rb @@ -13,7 +13,7 @@ def self.provider_or_provider_version_matches_selectors(selectors, allow_null_pr if allow_null_provider_version ors << { - Sequel[qualifier][:provider_id] => selectors.collect{ |s| s[:pacticipant_id] }, + Sequel[:lp][:provider_id] => selectors.collect{ |s| s[:pacticipant_id] }, Sequel[qualifier][:provider_version_id] => nil } end diff --git a/lib/pact_broker/matrix/quick_row.rb b/lib/pact_broker/matrix/quick_row.rb index 48e17b704..6d817e164 100644 --- a/lib/pact_broker/matrix/quick_row.rb +++ b/lib/pact_broker/matrix/quick_row.rb @@ -42,10 +42,6 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum Sequel[:lp][:consumer_id], Sequel[:consumers][:name].as(:consumer_name), Sequel[:lp][:provider_id], Sequel[:providers][:name].as(:provider_name) ] - PACTICIPANT_VERSION_IDS = [ - Sequel[:lp][:consumer_version_id], - Sequel[:lv][:provider_version_id] - ] associate(:many_to_one, :pact_publication, :class => "PactBroker::Pacts::PactPublication", :key => :pact_publication_id, :primary_key => :id) associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id) @@ -63,12 +59,9 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum select *SELECT_ALL_COLUMN_ARGS def distinct_integrations selectors - select(*(PACTICIPANT_NAMES_AND_IDS + PACTICIPANT_VERSION_IDS)) + select(*(PACTICIPANT_NAMES_AND_IDS)) .distinct .matching_selectors(selectors) - .from_self - .select(:consumer_name, :consumer_id, :provider_name, :provider_id) - .distinct end def matching_selectors selectors @@ -107,9 +100,8 @@ def matching_multiple_selectors(selectors) QueryBuilder.either_consumer_or_provider_was_specified_in_query(selectors, :lp) ) } - .from_self(alias: :t9) .where { - QueryBuilder.provider_or_provider_version_matches_selectors(selectors, true, :t9) + QueryBuilder.provider_or_provider_version_matches_selectors(selectors, true, :lv) } end