From 9e84ce7d020f8cdd9040eaec4c2b2727e1e4b7df Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 29 Oct 2019 09:16:27 +1100 Subject: [PATCH] feat: optimise latest_verification_ids_for_consumer_version_tags --- .../latest_pact_consumer_version_orders.rb | 3 +++ ..._verification_ids_for_consumer_version_tags.rb | 15 +++++++++++++++ ... latest_verification_ids_for_pact_versions.rb} | 0 ..._verification_ids_for_consumer_version_tags.rb | 13 +++++++++++++ 4 files changed, 31 insertions(+) rename db/ddl_statements/{latest_verification_ids_for_pact_versions_v001.rb => latest_verification_ids_for_pact_versions.rb} (100%) create mode 100644 db/migrations/20191031_optimise_latest_verification_ids_for_consumer_version_tags.rb diff --git a/db/ddl_statements/latest_pact_consumer_version_orders.rb b/db/ddl_statements/latest_pact_consumer_version_orders.rb index c7b77aee1..f3194f31e 100644 --- a/db/ddl_statements/latest_pact_consumer_version_orders.rb +++ b/db/ddl_statements/latest_pact_consumer_version_orders.rb @@ -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 diff --git a/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb b/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb index 0abd92e1f..f542eec80 100644 --- a/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +++ b/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb @@ -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" diff --git a/db/ddl_statements/latest_verification_ids_for_pact_versions_v001.rb b/db/ddl_statements/latest_verification_ids_for_pact_versions.rb similarity index 100% rename from db/ddl_statements/latest_verification_ids_for_pact_versions_v001.rb rename to db/ddl_statements/latest_verification_ids_for_pact_versions.rb diff --git a/db/migrations/20191031_optimise_latest_verification_ids_for_consumer_version_tags.rb b/db/migrations/20191031_optimise_latest_verification_ids_for_consumer_version_tags.rb new file mode 100644 index 000000000..a8e0d7d2e --- /dev/null +++ b/db/migrations/20191031_optimise_latest_verification_ids_for_consumer_version_tags.rb @@ -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