@@ -84,10 +84,15 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
84
84
select *SELECT_PACTICIPANT_IDS_ARGS
85
85
86
86
def distinct_integrations selectors
87
- select_pacticipant_ids
88
- . distinct
89
- . matching_selectors ( selectors )
90
- . from_self ( alias : :pacticipant_ids )
87
+ query = if selectors . size == 1
88
+ pacticipant_ids_matching_one_selector_optimised ( selectors )
89
+ else
90
+ select_pacticipant_ids
91
+ . distinct
92
+ . matching_multiple_selectors ( selectors )
93
+ end
94
+
95
+ query . from_self ( alias : :pacticipant_ids )
91
96
. select (
92
97
:consumer_id ,
93
98
Sequel [ :c ] [ :name ] . as ( :consumer_name ) ,
@@ -144,6 +149,29 @@ def matching_one_selector(selectors)
144
149
}
145
150
end
146
151
152
+ def pacticipant_ids_matching_one_selector_optimised ( selectors )
153
+ query_ids = QueryIds . from_selectors ( selectors )
154
+ distinct_pacticipant_ids_where_consumer_or_consumer_version_matches ( query_ids )
155
+ . union ( distinct_pacticipant_ids_where_provider_or_provider_version_matches ( query_ids ) )
156
+ end
157
+
158
+ def distinct_pacticipant_ids_where_consumer_or_consumer_version_matches ( query_ids )
159
+ select_pacticipant_ids
160
+ . distinct
161
+ . where {
162
+ QueryBuilder . consumer_or_consumer_version_matches ( query_ids , :p )
163
+ }
164
+ end
165
+
166
+ def distinct_pacticipant_ids_where_provider_or_provider_version_matches ( query_ids )
167
+ select_pacticipant_ids
168
+ . distinct
169
+ . inner_join_verifications
170
+ . where {
171
+ QueryBuilder . provider_or_provider_version_matches ( query_ids , :v )
172
+ }
173
+ end
174
+
147
175
# When the user has specified multiple selectors, we only want to join the verifications for
148
176
# the specified selectors. This is because of the behaviour of the left outer join.
149
177
# Imagine a pact has been verified by a provider version that was NOT specified in the selectors.
@@ -215,6 +243,10 @@ def join_provider_versions
215
243
def join_verifications
216
244
left_outer_join ( LV , LP_LV_JOIN , { table_alias : :v } )
217
245
end
246
+
247
+ def inner_join_verifications
248
+ join ( LV , LP_LV_JOIN , { table_alias : :v } )
249
+ end
218
250
end # end dataset_module
219
251
220
252
def success
0 commit comments