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 #14076 - remove unused Puppetclass hostgroups counter #3285
Conversation
def down | ||
add_column :puppetclasses, :hostgroups_count, :integer, :default => 0 | ||
HostgroupClass.all.each do |hgc| | ||
Puppetclass.increment_counter(:hostgroups_count, hgc.puppetclass_id) |
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.
Not sure if it's worth the trouble for a down migration, but we can calculate this entirely in the DB with a single SQL query.
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.
A query to group HostgroupClass by puppetclass_id and then update each puppetclass_id's counter?
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.
Something along the lines of:
UPDATE puppetclasses SET hostgroups_count = (SELECT count(*) FROM hostgroup_classes WHERE hostgroup_classes.class_id = puppetclasses.id)
Technically a nested query, but I think most DBs should be able to optimize it quite well. And without instantiating possibly thousands of objects.
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.
Thanks, updated.
This also needs fixing on this line: |
Thanks, fixed the rake task to not update this counter. |
Replaces #3282.