-
-
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(matrix): speed up query for UI by reducing the number of joins a…
…nd removing unncessary criteria (#332) * Add a created_at column to the latest pacts/latest verifications tables * Use the created_at columns newly created on latest_pact_publication_ids_for_consumer_versions and latest_verification_id_for_pact_version_and_provider_version to avoid having to join in the versions tables to order the matrix query rows * speed up matrix UI page by not joining verifications table when no version is specified * speed up matrix query by removing unncessary null check for provider versions when we are only querying by pacticipant names
- Loading branch information
Showing
20 changed files
with
221 additions
and
126 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
db/migrations/20200318_add_created_at_to_latest_pact_publications.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,9 @@ | ||
Sequel.migration do | ||
change do | ||
# TODO | ||
# alter_table(:latest_pact_publication_ids_for_consumer_versions) do | ||
# set_column_not_null(:created_at) | ||
# end | ||
add_column(:latest_pact_publication_ids_for_consumer_versions, :created_at, DateTime) | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
db/migrations/20200319_add_created_at_to_latest_verifications.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,9 @@ | ||
Sequel.migration do | ||
change do | ||
# TODO | ||
# alter_table(:latest_verification_id_for_pact_version_and_provider_version) do | ||
# set_column_not_null(:created_at) | ||
# end | ||
add_column(:latest_verification_id_for_pact_version_and_provider_version, :created_at, DateTime) | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
lib/pact_broker/db/data_migrations/set_created_at_for_latest_pact_publications.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 @@ | ||
require 'pact_broker/db/data_migrations/helpers' | ||
|
||
module PactBroker | ||
module DB | ||
module DataMigrations | ||
class SetCreatedAtForLatestPactPublications | ||
def self.call connection | ||
# pact ordering goes by creation date of the consumer version | ||
connection[:latest_pact_publication_ids_for_consumer_versions] | ||
query = "UPDATE latest_pact_publication_ids_for_consumer_versions | ||
SET created_at = (SELECT created_at | ||
FROM versions | ||
WHERE id = latest_pact_publication_ids_for_consumer_versions.consumer_version_id) | ||
WHERE created_at IS NULL" | ||
connection.run(query) | ||
end | ||
|
||
def self.columns_exist?(connection) | ||
column_exists?(connection, :latest_pact_publication_ids_for_consumer_versions, :created_at) && | ||
column_exists?(connection, :pact_publications, :created_at) | ||
end | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
lib/pact_broker/db/data_migrations/set_created_at_for_latest_verifications.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,24 @@ | ||
require 'pact_broker/db/data_migrations/helpers' | ||
|
||
module PactBroker | ||
module DB | ||
module DataMigrations | ||
class SetCreatedAtForLatestVerifications | ||
def self.call connection | ||
connection[:latest_verification_id_for_pact_version_and_provider_version] | ||
query = "UPDATE latest_verification_id_for_pact_version_and_provider_version | ||
SET created_at = (SELECT created_at | ||
FROM verifications | ||
WHERE id = latest_verification_id_for_pact_version_and_provider_version.verification_id) | ||
WHERE created_at is null" | ||
connection.run(query) | ||
end | ||
|
||
def self.columns_exist?(connection) | ||
column_exists?(connection, :latest_verification_id_for_pact_version_and_provider_version, :created_at) && | ||
column_exists?(connection, :verifications, :created_at) | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
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
Oops, something went wrong.