Skip to content

Commit

Permalink
feat(matrix): optimise query to determine integrations, again
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 13, 2020
1 parent dca0ad4 commit 44e78ad
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions lib/pact_broker/matrix/quick_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
select *SELECT_PACTICIPANT_IDS_ARGS

def distinct_integrations selectors
select_pacticipant_ids
.distinct
.matching_selectors(selectors)
.from_self(alias: :pacticipant_ids)
query = if selectors.size == 1
pacticipant_ids_matching_one_selector_optimised(selectors)
else
select_pacticipant_ids
.distinct
.matching_multiple_selectors(selectors)
end

query.from_self(alias: :pacticipant_ids)
.select(
:consumer_id,
Sequel[:c][:name].as(:consumer_name),
Expand Down Expand Up @@ -144,6 +149,29 @@ def matching_one_selector(selectors)
}
end

def pacticipant_ids_matching_one_selector_optimised(selectors)
query_ids = QueryIds.from_selectors(selectors)
distinct_pacticipant_ids_where_consumer_or_consumer_version_matches(query_ids)
.union(distinct_pacticipant_ids_where_provider_or_provider_version_matches(query_ids))
end

def distinct_pacticipant_ids_where_consumer_or_consumer_version_matches(query_ids)
select_pacticipant_ids
.distinct
.where {
QueryBuilder.consumer_or_consumer_version_matches(query_ids, :p)
}
end

def distinct_pacticipant_ids_where_provider_or_provider_version_matches(query_ids)
select_pacticipant_ids
.distinct
.inner_join_verifications
.where {
QueryBuilder.provider_or_provider_version_matches(query_ids, :v)
}
end

# When the user has specified multiple selectors, we only want to join the verifications for
# the specified selectors. This is because of the behaviour of the left outer join.
# Imagine a pact has been verified by a provider version that was NOT specified in the selectors.
Expand Down Expand Up @@ -215,6 +243,10 @@ def join_provider_versions
def join_verifications
left_outer_join(LV, LP_LV_JOIN, { table_alias: :v } )
end

def inner_join_verifications
join(LV, LP_LV_JOIN, { table_alias: :v } )
end
end # end dataset_module

def success
Expand Down

0 comments on commit 44e78ad

Please sign in to comment.