-
-
Notifications
You must be signed in to change notification settings - Fork 178
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 for determining latest verification for consumer…
… and provider
- Loading branch information
Showing
4 changed files
with
49 additions
and
29 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
db/ddl_statements/latest_verification_ids_for_consumer_and_provider.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,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" |
15 changes: 4 additions & 11 deletions
15
db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.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
24 changes: 6 additions & 18 deletions
24
db/migrations/20180614_update_latest_verification_ids_for_consumer_and_provider.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 |
---|---|---|
@@ -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 |
14 changes: 14 additions & 0 deletions
14
db/migrations/20201026_update_latest_verification_ids_for_consumer_and_provider.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,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 |