Skip to content
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 #20057 - fix duplicate akey repo sets #6973

Merged
merged 1 commit into from Oct 6, 2017

Conversation

jlsherrill
Copy link
Member

this fixes duplicate repository sets from being returned
when listing them for an activation key. In addition this improves performance
by using a single api call for all product content in the org,
as well as using a presenter to only fetch the activation key overrides
once, instead of once per product content.

In addition this updates the redhat repos page to use this new
content fetching method to speed up that page as well.

@theforeman-bot
Copy link

Issues: #20057

@theforeman-bot
Copy link

There were the following issues with the commit message:

  • commit message for d719c7d9018d5e8e88cfa22d8dbfa9df7da26f9a is not wrapped at 72nd column

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

provider.products.each do |product|
product.displayable_product_contents.each do |prod_content|
selected_contents = product_content.select { |product_content| product_content.product_id == product.id }.select(&:displayable?)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shadowing outer local variable - product_content.

@parthaa parthaa changed the title Fixes #20057 - fix dupliate akey repo sets Fixes #20057 - fix duplicate akey repo sets Sep 28, 2017
@parthaa parthaa self-assigned this Sep 28, 2017
@@ -38,6 +38,32 @@ def content_access_mode
self.owner_details['contentAccessMode']
end

def enabled_product_content(for_repositories)
return [] if for_repositories && for_repositories.empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for_repositories.blank?

def enabled_product_content(for_repositories)
return [] if for_repositories && for_repositories.empty?
repositories = for_repositories.select([:product_id, :content_id]).to_a
content_ids = repositories.map(&:content_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are just using content_id from here then why do you need [:product_id, :content_id]

end

def filtered_product_content
cp_products = Katello::Resources::Candlepin::Product.all(Organization.first.label, [:id, :productContent])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont remember exactly how this works. Can you enlighten me on why you are getting all products from Organization.first as opposed to current org?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should be self ;) /me thinks i copy and pasted from my console

@jlsherrill
Copy link
Member Author

@parthaa updated

@@ -399,6 +399,10 @@ def import(organization_name, path_to_file, options)
self.post(path, {:import => File.new(path_to_file, 'rb')}, self.default_headers.except('content-type'))
end

def product_content(organization_name)
Product.all(organization_name, [:id, :productContent])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no chance this would be confused with '::Katello::Product' right ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, we do things in similar places in this file

@parthaa
Copy link
Contributor

parthaa commented Oct 3, 2017

Code looks good to me. But the "show all " in the repository sets page seems to show me non yum repos also (like I saw paths pointing to ostree and docker). In the master version the docker ones were getting ignored. And I don't know if ostree stuff can be overridden. So might not not want to include that,

end
content.uniq
considered_products = content_access_mode_all ? all_products : self.products
repositories = Katello::Repository.where(:product_id => considered_products)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to limit this to type yum.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by using .subscribable

@parthaa
Copy link
Contributor

parthaa commented Oct 3, 2017

I definitely notice the perf improvements definitely and no dupes. Nice work. Address the above comment and should be good to go.

to_return = []

cp_products.each do |product_hash|
product = ::Katello::Product.find_by(:cp_id => product_hash['id'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cp_id is not org safe!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-          product = ::Katello::Product.find_by(:cp_id => product_hash['id'])
+          product = ::Katello::Product.find_by(:organization_id => self.id, :cp_id => product_hash['id'])

@parthaa
Copy link
Contributor

parthaa commented Oct 3, 2017

Not to overcomplicate this PR but can you check if the content hosts could use this logic for subs and repo sets... My guess is they are suffering from the same ailments

@parthaa
Copy link
Contributor

parthaa commented Oct 3, 2017

Rh Repos page

Before PR
 Completed 200 OK in 26777ms (Views: 26283.9ms | ActiveRecord: 85.3ms)

After PR
 Completed 200 OK in 8058ms (Views: 6534.3ms | ActiveRecord: 1156.0ms)

@jlsherrill
Copy link
Member Author

Updated to fix multi-org issue, added to content host repo sets listing, and sped it up even more by using more specific includes on the candlepin request.

@theforeman-bot
Copy link

There were the following issues with the commit message:

  • 2f345b3329c6622fdf4bebe2fff2c1382893657d must be in the format fixes #redmine_number - brief description

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@jlsherrill
Copy link
Member Author

Updated to move to a service as much as i could. let me know if you like it better

content = pcf.product_content

overrides = @activation_key.content_overrides
content.map! { |pc| ProductContentPresenter.new(pc, overrides) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the refactoring but I think you could DRY it up further by adding overrides logic to the Finder and make him return ProductContentPresenter... That would mean we can use the same logic for both AK and CH

@theforeman-bot
Copy link

There were the following issues with the commit message:

  • 310cf1e3d5d39ed823bad3a5aee85bd75d0ff87b must be in the format fixes #redmine_number - brief description

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@jlsherrill
Copy link
Member Author

@parthaa updated!

@parthaa
Copy link
Contributor

parthaa commented Oct 5, 2017

APJ

this fixes duplicate repository sets from being returned
when listing them for an activation key.  In addition this improves
performance by using a single api call for all product content in
the org, as well as using a presenter to only fetch the activation
key overrides once, instead of once per product content.

In addition this updates the redhat repos page to use this new
content fetching method to speed up that page as well.

Move product content to a service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants