diff --git a/lib/pact_broker/matrix/every_row.rb b/lib/pact_broker/matrix/every_row.rb index e2b1f8635..4c882b09f 100644 --- a/lib/pact_broker/matrix/every_row.rb +++ b/lib/pact_broker/matrix/every_row.rb @@ -17,15 +17,19 @@ class EveryRow < PactBroker::Matrix::QuickRow Sequel[:p][:created_at].as(:consumer_version_created_at), Sequel[:p][:id].as(:pact_order) ] + VERIFICATION_COLUMNS = [ Sequel[:v][:id].as(:verification_id), Sequel[:v][:provider_version_id], Sequel[:v][:created_at].as(:provider_version_created_at) ] + JOINED_VERIFICATION_COLUMNS = [:id, :pact_version_id, :provider_id, :provider_version_id, :created_at] + ALL_COLUMNS = PACT_COLUMNS + VERIFICATION_COLUMNS SELECT_ALL_COLUMN_ARGS = [:select_all_columns] + ALL_COLUMNS + dataset_module do select(*SELECT_ALL_COLUMN_ARGS) @@ -33,9 +37,23 @@ def join_verifications left_outer_join(:verifications, P_V_JOIN, { table_alias: :v } ) end + def inner_join_verifications + join(:verifications, P_V_JOIN, { table_alias: :v } ) + end + + def inner_join_verifications_matching_one_selector_provider_or_provider_version(query_ids) + verifications = db[:verifications] + .select(*JOINED_VERIFICATION_COLUMNS) + .where { + QueryBuilder.provider_or_provider_version_matches(query_ids) + } + + join(verifications, P_V_JOIN, { table_alias: :v } ) + end + def verifications_for(query_ids) db[:verifications] - .select(:id, :pact_version_id, :provider_id, :provider_version_id, :created_at) + .select(*JOINED_VERIFICATION_COLUMNS) .where { Sequel.&( QueryBuilder.consumer_in_pacticipant_ids(query_ids), diff --git a/lib/pact_broker/matrix/quick_row.rb b/lib/pact_broker/matrix/quick_row.rb index 04f5b5f74..c2a467db0 100644 --- a/lib/pact_broker/matrix/quick_row.rb +++ b/lib/pact_broker/matrix/quick_row.rb @@ -45,6 +45,15 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum Sequel[:v][:verification_id], Sequel[:v][:created_at].as(:provider_version_created_at) ] + + JOINED_VERIFICATION_COLUMNS = [ + :verification_id, + :provider_version_id, + :pact_version_id, + :provider_id, + :created_at + ] + LAST_ACTION_DATE = Sequel.lit("CASE WHEN (provider_version_created_at IS NOT NULL AND provider_version_created_at > consumer_version_created_at) THEN provider_version_created_at ELSE consumer_version_created_at END").as(:last_action_date) ALL_COLUMNS = PACT_COLUMNS + VERIFICATION_COLUMNS @@ -146,10 +155,15 @@ def default_scope # When we have one selector, we need to join ALL the verifications to find out # what integrations exist def matching_one_selector(selectors) - join_verifications + query_ids = QueryIds.from_selectors(selectors) + rows_where_selector_matches_consumer_cols = join_verifications .where { - QueryBuilder.consumer_or_consumer_version_or_provider_or_provider_or_provider_version_match(QueryIds.from_selectors(selectors), :p, :v) + QueryBuilder.consumer_or_consumer_version_matches(query_ids, :p) } + + rows_where_selector_matches_provider_cols = inner_join_verifications_matching_one_selector_provider_or_provider_version(query_ids) + + rows_where_selector_matches_consumer_cols.union(rows_where_selector_matches_provider_cols) end def pacticipant_ids_matching_one_selector_optimised(selectors) @@ -229,9 +243,19 @@ def join_verifications_for(query_ids) left_outer_join(verifications_for(query_ids), LP_LV_JOIN, { table_alias: :v } ) end + def inner_join_verifications_matching_one_selector_provider_or_provider_version(query_ids) + verifications = db[LV] + .select(*JOINED_VERIFICATION_COLUMNS) + .where { + QueryBuilder.provider_or_provider_version_matches(query_ids) + } + + join(verifications, LP_LV_JOIN, { table_alias: :v } ) + end + def verifications_for(query_ids) db[LV] - .select(:verification_id, :provider_version_id, :pact_version_id, :provider_id, :created_at) + .select(*JOINED_VERIFICATION_COLUMNS) .where { Sequel.&( QueryBuilder.consumer_in_pacticipant_ids(query_ids),