-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimise query to find latest verification for consumer version…
… tag
- Loading branch information
Showing
3 changed files
with
52 additions
and
17 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# The latest verification id for each consumer version tag | ||
# This is not: | ||
# find latest pacticipant version with given tag | ||
# -> find the latest pact | ||
# -> find the latest verification | ||
# because the latest pacticipant version with the tag might not have a pact, | ||
# and the latest pact might not have a verification. | ||
|
||
# This is: | ||
# join the tags and the pacticipant versions and the verifications and find the "latest" row | ||
|
||
LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V1 = "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_publications_by_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 | ||
group by pv.pacticipant_id, lpp.consumer_id, t.name" | ||
|
||
LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V2 = "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 | ||
group by pv.pacticipant_id, lpp.consumer_id, t.name" |
20 changes: 3 additions & 17 deletions
20
db/migrations/20180523_create_latest_verifications_for_consumer_version_tags.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
db/migrations/20191025_optimise_latest_verification_ids_for_cv_tags.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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_V2) | ||
end | ||
|
||
down do | ||
create_or_replace_view(:latest_verification_ids_for_consumer_version_tags, LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V1) | ||
end | ||
end |