Skip to content

Commit

Permalink
feat: optimise query for determining latest verification for consumer…
Browse files Browse the repository at this point in the history
… and provider
  • Loading branch information
bethesque committed Oct 25, 2020
1 parent de4fd20 commit 7889b05
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V1 = "select
pv.pacticipant_id as provider_id,
lpp.consumer_id,
max(v.id) as latest_verification_id
from verifications v
join latest_pact_publications_by_consumer_versions lpp
on v.pact_version_id = lpp.pact_version_id
join versions pv
on v.provider_version_id = pv.id
group by pv.pacticipant_id, lpp.consumer_id"

LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V2 = "select
provider_id,
consumer_id,
max(id) as latest_verification_id
from verifications v
group by provider_id, consumer_id"


LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V3 = "select
provider_id,
consumer_id,
max(verification_id) as latest_verification_id
from latest_verification_id_for_pact_version_and_provider_version v
group by provider_id, consumer_id"
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
require_relative '../ddl_statements/latest_verification_ids_for_consumer_and_provider'

Sequel.migration do
up do
# The latest verification id for each consumer version tag
# The latest verification id for each consumer/provider
create_view(:latest_verification_ids_for_consumer_and_provider,
"select
pv.pacticipant_id as provider_id,
lpp.consumer_id,
max(v.id) as latest_verification_id
from verifications v
join latest_pact_publications_by_consumer_versions lpp
on v.pact_version_id = lpp.pact_version_id
join versions pv
on v.provider_version_id = pv.id
group by pv.pacticipant_id, lpp.consumer_id")
LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V1)

# The most recent verification for each consumer/consumer version tag/provider
latest_verifications = from(:verifications)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
require_relative '../ddl_statements/latest_verification_ids_for_consumer_and_provider'

Sequel.migration do
up do
# The latest verification id for each consumer version tag
# The latest verification id for each consumer/provider
create_or_replace_view(:latest_verification_ids_for_consumer_and_provider,
"select
provider_id,
consumer_id,
max(id) as latest_verification_id
from verifications v
group by provider_id, consumer_id")
LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V2)
end

down do
# The latest verification id for each consumer version tag
# The latest verification id for each consumer/provider
create_or_replace_view(:latest_verification_ids_for_consumer_and_provider,
"select
pv.pacticipant_id as provider_id,
lpp.consumer_id,
max(v.id) as latest_verification_id
from verifications v
join latest_pact_publications_by_consumer_versions lpp
on v.pact_version_id = lpp.pact_version_id
join versions pv
on v.provider_version_id = pv.id
group by pv.pacticipant_id, lpp.consumer_id")
LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V1)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative 'migration_helper'
require_relative '../ddl_statements/latest_verification_ids_for_consumer_and_provider'

Sequel.migration do
up do
create_or_replace_view(:latest_verification_ids_for_consumer_and_provider,
LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V3)
end

down do
create_or_replace_view(:latest_verification_ids_for_consumer_and_provider,
LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V2)
end
end

0 comments on commit 7889b05

Please sign in to comment.