New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #21691 - clean installed packages on upgrade #7069
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class CleanupInstalledPackages < ActiveRecord::Migration | ||
def up | ||
create_table "katello_installed_packages_new", force: :cascade do |t| | ||
t.string "name", limit: 255, null: false | ||
t.string "nvra", limit: 255, null: false | ||
end | ||
|
||
create_table "katello_host_installed_packages_new", force: :cascade do |t| | ||
t.integer "host_id", null: false | ||
t.integer "installed_package_id", null: false | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a unique index for the combination columns here. This should speed up the lookup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There arne't any lookups being done on this table? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I guess add it on the |
||
#Copy unique entires to new table | ||
execute('insert into katello_installed_packages_new(nvra, name) | ||
select distinct(nvra) as nvra, name from katello_installed_packages') | ||
|
||
#copy associations | ||
execute(' | ||
insert into katello_host_installed_packages_new (host_id, installed_package_id) | ||
select distinct katello_host_installed_packages.host_id, katello_installed_packages_new.id | ||
from katello_installed_packages | ||
inner join katello_host_installed_packages on katello_host_installed_packages.installed_package_id = katello_installed_packages.id | ||
inner join katello_installed_packages_new on katello_installed_packages_new.nvra = katello_installed_packages.nvra') | ||
|
||
remove_foreign_key :katello_host_installed_packages, name: "katello_host_installed_packages_installed_package_id" | ||
remove_foreign_key :katello_host_installed_packages, name: "katello_host_installed_packages_host_id" | ||
|
||
drop_table "katello_installed_packages" | ||
drop_table "katello_host_installed_packages" | ||
|
||
rename_table "katello_installed_packages_new", "katello_installed_packages" | ||
rename_table "katello_host_installed_packages_new", "katello_host_installed_packages" | ||
|
||
add_index :katello_installed_packages, [:name, :nvra] | ||
|
||
add_foreign_key "katello_host_installed_packages", "hosts", | ||
:name => "katello_host_installed_packages_host_id", :column => "host_id" | ||
|
||
add_foreign_key "katello_host_installed_packages", "katello_installed_packages", | ||
:name => "katello_host_installed_packages_installed_package_id", :column => "installed_package_id" | ||
|
||
#At this point, everything should be back to where it was (sans-duplicates) | ||
# Now do new things | ||
add_index :katello_installed_packages, [:nvra], :unique => true | ||
add_index :katello_host_installed_packages, [:host_id, :installed_package_id], :unique => true, :name => :katello_host_installed_packages_h_id_ip_id | ||
Setting.where(:name => 'bulk_query_installed_packages', :category => 'Setting::Content').delete_all | ||
end | ||
|
||
def down | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am debating if you should do
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that is needed? The db should be in the same state as before, just with de-duplicate data. |
||
#only revert new things | ||
remove_index :katello_installed_packages, [:nvra] | ||
remove_index :katello_host_installed_packages, :name => :katello_host_installed_packages_h_id_ip_id | ||
#Setting will be recreated on startup | ||
end | ||
end |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a unique index to this column to speed up the search
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that it would help, but i can time it and see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested and with the index it took about ~4 minutes more.