Skip to content

Commit 0720655

Browse files
committed
fix(dashboard api): remove expensive queries for unused data
1 parent 0e3dcc0 commit 0720655

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/pact_broker/index/service.rb

+17-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ class Service
1313
extend PactBroker::Services
1414
extend PactBroker::Logging
1515

16+
# This method provides data for both the OSS server side rendered index (with and without tags)
17+
# and the Pactflow UI. It really needs to be broken into to separate methods, as it's getting too messy
18+
# supporting both
19+
1620
def self.find_index_items options = {}
1721
rows = PactBroker::Matrix::HeadRow
1822
.select_all_qualified
1923
.eager(:latest_triggered_webhooks)
2024
.eager(:webhooks)
2125

26+
# pactflow
2227
rows = rows.consumer(options[:consumer_name]) if options[:consumer_name]
2328
rows = rows.provider(options[:provider_name]) if options[:provider_name]
2429

@@ -29,9 +34,17 @@ def self.find_index_items options = {}
2934
rows = rows.where(consumer_version_tag_name: options[:tags]).or(consumer_version_tag_name: nil)
3035
end
3136
rows = rows.eager(:consumer_version_tags)
32-
.eager(:provider_version_tags)
33-
.eager(:latest_verification_for_consumer_version_tag)
34-
.eager(:latest_verification_for_consumer_and_provider)
37+
.eager(:provider_version_tags)
38+
39+
if !options[:dashboard] # pactflow
40+
# The latest_verification_for_consumer_version_tag query is very slow when there is lots of data,
41+
# and it is only used when calculating latest_verification_for_pseudo_branch,
42+
# so only load it if we need it
43+
rows = rows.eager(:latest_verification_for_consumer_version_tag)
44+
.eager(:latest_verification_for_consumer_and_provider)
45+
end
46+
47+
3548
end
3649
rows = rows.all.group_by(&:pact_publication_id).values.collect{ | rows| Matrix::AggregatedRow.new(rows) }
3750

@@ -45,7 +58,7 @@ def self.find_index_items options = {}
4558
# or it's not verified.
4659
# For backwards compatiblity with the existing UI, don't change the 'stale' concept for the OSS
4760
# UI - just ensure we don't use it for the new dashboard endpoint with the consumer/provider specified.
48-
latest_verification = if options[:dashboard]
61+
latest_verification = if options[:dashboard] # pactflow
4962
row.latest_verification_for_pact_version
5063
else
5164
row.latest_verification_for_pseudo_branch

0 commit comments

Comments
 (0)