Skip to content

Commit 704944b

Browse files
committed
feat(matrix): optimise the query that determines the integrations
1 parent afde01e commit 704944b

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

lib/pact_broker/matrix/query_builder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.provider_or_provider_version_matches_selectors(selectors, allow_null_pr
1313

1414
if allow_null_provider_version
1515
ors << {
16-
Sequel[qualifier][:provider_id] => selectors.collect{ |s| s[:pacticipant_id] },
16+
Sequel[:lp][:provider_id] => selectors.collect{ |s| s[:pacticipant_id] },
1717
Sequel[qualifier][:provider_version_id] => nil
1818
}
1919
end

lib/pact_broker/matrix/quick_row.rb

+2-10
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
4242
Sequel[:lp][:consumer_id], Sequel[:consumers][:name].as(:consumer_name),
4343
Sequel[:lp][:provider_id], Sequel[:providers][:name].as(:provider_name)
4444
]
45-
PACTICIPANT_VERSION_IDS = [
46-
Sequel[:lp][:consumer_version_id],
47-
Sequel[:lv][:provider_version_id]
48-
]
4945

5046
associate(:many_to_one, :pact_publication, :class => "PactBroker::Pacts::PactPublication", :key => :pact_publication_id, :primary_key => :id)
5147
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
6359
select *SELECT_ALL_COLUMN_ARGS
6460

6561
def distinct_integrations selectors
66-
select(*(PACTICIPANT_NAMES_AND_IDS + PACTICIPANT_VERSION_IDS))
62+
select(*(PACTICIPANT_NAMES_AND_IDS))
6763
.distinct
6864
.matching_selectors(selectors)
69-
.from_self
70-
.select(:consumer_name, :consumer_id, :provider_name, :provider_id)
71-
.distinct
7265
end
7366

7467
def matching_selectors selectors
@@ -107,9 +100,8 @@ def matching_multiple_selectors(selectors)
107100
QueryBuilder.either_consumer_or_provider_was_specified_in_query(selectors, :lp)
108101
)
109102
}
110-
.from_self(alias: :t9)
111103
.where {
112-
QueryBuilder.provider_or_provider_version_matches_selectors(selectors, true, :t9)
104+
QueryBuilder.provider_or_provider_version_matches_selectors(selectors, true, :lv)
113105
}
114106
end
115107

0 commit comments

Comments
 (0)