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 #28894 - load the pools from AR database instead of Candlepin #8550

Merged
merged 1 commit into from
Feb 2, 2020

Conversation

matt8754
Copy link
Contributor

In case there is a large list of pools, this will improve the speed when loading up the subscription page.

@theforeman-bot
Copy link

Can one of the admins verify this patch?

@matt8754 matt8754 changed the title Fix #28894 load the pools from AR database instead of Candlepin Fix #28894 - load the pools from AR database instead of Candlepin Jan 30, 2020
@matt8754 matt8754 changed the title Fix #28894 - load the pools from AR database instead of Candlepin Fixes #28894 - load the pools from AR database instead of Candlepin Jan 30, 2020
@chris1984
Copy link
Member

[ok to test]

@chris1984
Copy link
Member

@matt8754 how is a good way to test this, how many subs/hosts do you need?

@jturel jturel self-assigned this Jan 31, 2020
@jturel
Copy link
Member

jturel commented Jan 31, 2020

This is a good change. I can see an unnecessary call being made to candlepin

before:

INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/Default_Organization/pools?add_future=true&attribute=unmapped_guests_only:!true
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/pools/4028fac46fc959b7016fc976f5800a30
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/Default_Organization/products/SER0482/?
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/pools/4028fac46fd2c37b016ffd7bc1e8039c
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/Default_Organization/products/RH00005/?
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/pools/4028fac46fd2c37b016ff327e9520167
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/Default_Organization/products/605248846626/?

after:

INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/pools/4028fac46fc959b7016fc976f5800a30
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/Default_Organization/products/SER0482/?
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/pools/4028fac46fd2c37b016ffd7bc1e8039c
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/Default_Organization/products/RH00005/?
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/pools/4028fac46fd2c37b016ff327e9520167
INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/Default_Organization/products/605248846626/?

I verified that this does not affect the output of the API.

@@ -5,8 +5,7 @@ module Glue::Candlepin::CandlepinObject
module ClassMethods
def get_for_organization(organization)
# returns objects from AR database rather than candlepin data
pool_ids = self.get_for_owner(organization.label).collect { |x| x['id'] }
self.where(:cp_id => pool_ids)
self.where(:organization => organization)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this method is only used in one place, and I don't think it makes sense to have a separate method anymore since it only has a single where clause.

Let's remove this method and update subscriptions_controller.rb:

+++ b/app/controllers/katello/api/v2/subscriptions_controller.rb
@@ -65,7 +65,7 @@ module Katello
       return available_for_activation_key if params[:available_for] == "activation_key"
       collection = Pool.readable
       collection = collection.where(:unmapped_guest => false)
-      collection = collection.get_for_organization(Organization.find(params[:organization_id])) if params[:organization_id]
+      collection = collection.where(organization: Organization.find(params[:organization_id])) if params[:organization_id]
       collection = collection.for_activation_key(@activation_key) if params[:activation_key_id]
       collection
     end

I think the tests will need to be updated. You can verify locally with:

ktest ./test/controllers/api/v2/subscriptions_controller_test.rb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, Jonathon. This is exactly what I came out first. However, I was worried about breaking the tests as they call get_for_organization. I'll take a look further for that.

@matt8754
Copy link
Contributor Author

@matt8754 how is a good way to test this, how many subs/hosts do you need?

Ideally, it would be good to have 3K+ hypervisors with the VDC sub attached. This would match the customer's env from which the issue happens.

In case there is a large list of pools, this will improve the speed when loading up the subscription page.
@jturel
Copy link
Member

jturel commented Feb 1, 2020

[test katello]

Copy link
Member

@jturel jturel left a comment

Choose a reason for hiding this comment

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

ACK. Thank you @matt8754 - we appreciate your contribution.

@jturel jturel merged commit 9b47cf0 into Katello:master Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants