Skip to content

Commit

Permalink
feat(matrix): optimise the query that determines the integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Dec 30, 2019
1 parent afde01e commit 704944b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/matrix/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions lib/pact_broker/matrix/quick_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 704944b

Please sign in to comment.