-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add duplicate columns to tags table to reduce joins
* feat: add pacticipant id and version order columns to tags * chore: update setting of extra columns in tags * feat: optimise query to find latest tags * chore: more optimisations * chore: optimise latest tagged pact consumer version orders * chore: make tests pass * chore: rename migrations and fix tests * chore: remove commented old code [ci-skip] * chore: add custom index for tag ordering * chore: optimise index by determining latest tag status using eager loaded head_tag * chore: update sequel model annotations * chore: update indexes * chore: raise error if running db:annotate without INSTALL_PG=true [ci-skip] * chore: code climate * chore: undo changes to pry.rb [ci-skip] * chore: update pry.rb [ci-skip] * docs: add docs about the regression tests [ci-skip] * chore: use eager loaded head_pact_publications for tags to determine the head pact tags * chore: optimise 'latest pact publication by tag' query by removing versions join * chore: optimise PactPublication.latest_for_consumer_tag * refactor: rewrite queries for selecting pacts for index page * docs: comment [ci-skip]
- Loading branch information
Showing
47 changed files
with
1,080 additions
and
333 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LATEST_TAGGED_PACT_PUBLICATIONS = "select lp.*, o.tag_name | ||
from latest_pact_publications_by_consumer_versions lp | ||
inner join latest_tagged_pact_consumer_version_orders o | ||
on lp.consumer_id = o.consumer_id | ||
and lp.provider_id = o.provider_id | ||
and lp.consumer_version_order = latest_consumer_version_order" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require_relative 'migration_helper' | ||
|
||
include PactBroker::MigrationHelper | ||
|
||
Sequel.migration do | ||
change do | ||
alter_table(:tags) do | ||
# TODO set_column_not_null(:pacticipant_id) | ||
# TODO set_column_not_null(:version_order) | ||
add_column(:pacticipant_id, Integer) | ||
add_column(:version_order, Integer) | ||
add_index(:version_order, name: "tags_version_order_index") | ||
add_index(:version_id, name: "tags_version_id_index") | ||
add_index(:pacticipant_id, name: "tags_pacticipant_id_index") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require_relative 'migration_helper' | ||
|
||
include PactBroker::MigrationHelper | ||
|
||
Sequel.migration do | ||
up do | ||
if postgres? | ||
run("CREATE INDEX tags_pacticipant_id_name_version_order_desc_index ON tags (pacticipant_id, name, version_order DESC);") | ||
run("CREATE INDEX versions_pacticipant_id_order_desc_index ON versions (pacticipant_id, \"order\" DESC);") | ||
else | ||
alter_table(:tags) do | ||
add_index([:pacticipant_id, :name, :version_order], name: "tags_pacticipant_id_name_version_order_index") | ||
end | ||
end | ||
end | ||
|
||
down do | ||
if postgres? | ||
run("DROP INDEX tags_pacticipant_id_name_version_order_desc_index") | ||
run("DROP INDEX versions_pacticipant_id_order_desc_index") | ||
else | ||
alter_table(:tags) do | ||
drop_index([:pacticipant_id, :name, :version_order], name: "tags_pacticipant_id_name_version_order_index") | ||
end | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
db/migrations/20210207_optimise_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,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_V4) | ||
end | ||
|
||
down do | ||
create_or_replace_view(:latest_verification_ids_for_consumer_version_tags, | ||
LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V3) | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
db/migrations/20210208_optimise_latest_tagged_pact_cv_orders.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,13 @@ | ||
require_relative '../ddl_statements' | ||
|
||
Sequel.migration do | ||
up do | ||
create_or_replace_view(:latest_tagged_pact_consumer_version_orders, | ||
latest_tagged_pact_consumer_version_orders_v4(self)) | ||
end | ||
|
||
down do | ||
create_or_replace_view(:latest_tagged_pact_consumer_version_orders, | ||
latest_tagged_pact_consumer_version_orders_v3(self)) | ||
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
29 changes: 29 additions & 0 deletions
29
lib/pact_broker/db/data_migrations/set_extra_columns_for_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,29 @@ | ||
require 'pact_broker/db/data_migrations/helpers' | ||
|
||
module PactBroker | ||
module DB | ||
module DataMigrations | ||
class SetExtraColumnsForTags | ||
extend Helpers | ||
|
||
def self.call(connection) | ||
if columns_exist?(connection, :tags, [:version_id, :pacticipant_id]) && | ||
columns_exist?(connection, :versions, [:id, :pacticipant_id]) | ||
connection[:tags].update( | ||
pacticipant_id: connection[:versions].select(:pacticipant_id) | ||
.where(Sequel[:versions][:id] => Sequel[:tags][:version_id]) | ||
) | ||
end | ||
|
||
if columns_exist?(connection, :tags, [:version_id, :version_order]) && | ||
columns_exist?(connection, :versions, [:id, :order]) | ||
connection[:tags].update( | ||
version_order: connection[:versions].select(:order) | ||
.where(Sequel[:versions][:id] => Sequel[:tags][:version_id]) | ||
) | ||
end | ||
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
Oops, something went wrong.