Skip to content

Commit

Permalink
feat: optimise latest_verification_ids_for_consumer_version_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 28, 2019
1 parent a3ea6fc commit 9e84ce7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions db/ddl_statements/latest_pact_consumer_version_orders.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# The consumer id, provider id, and consumer version order
# for the latest consumer version that has a pact with that provider.

def latest_pact_consumer_version_orders_v1(connection = nil)
"select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order
from all_pact_publications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@
join versions pv
on v.provider_version_id = pv.id
group by pv.pacticipant_id, lpp.consumer_id, t.name"

LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V3 = "select
pv.pacticipant_id as provider_id,
lpp.consumer_id,
t.name as consumer_version_tag_name,
max(v.id) as latest_verification_id
from verifications v
join latest_pact_publication_ids_for_consumer_versions lpp
on v.pact_version_id = lpp.pact_version_id
join tags t
on lpp.consumer_version_id = t.version_id
join versions pv
on v.provider_version_id = pv.id
where v.id in (select latest_verification_id from latest_verification_ids_for_pact_versions)
group by pv.pacticipant_id, lpp.consumer_id, t.name"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_relative '../ddl_statements'

Sequel.migration do
up do
create_or_replace_view(:latest_verification_ids_for_consumer_version_tags,
LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V3)
end

down do
create_or_replace_view(:latest_verification_ids_for_consumer_version_tags,
LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V2)
end
end

0 comments on commit 9e84ce7

Please sign in to comment.