| Summary: | GetConsumer(uuid) & regenerateIdentityCertificates(uuid) call consumerCurator.verifyAndLookupConsumer(uuid) redundantly | ||
|---|---|---|---|
| Product: | [Community] Candlepin | Reporter: | Craig Stanford <cstanfor> |
| Component: | candlepin | Assignee: | William Poteat <wpoteat> |
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Katello QA List <katello-qa-list> |
| Severity: | low | Docs Contact: | |
| Priority: | medium | ||
| Version: | 2.0 | CC: | bcourt, wpoteat |
| Target Milestone: | --- | Keywords: | Triaged |
| Target Release: | --- | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2016-07-22 14:39:55 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
master commit 1d1727455abefc0479c0a5ef26a730d87af6ee55 Moving to closed per the updated candlepin process for bugs that have been merged or have been taken care of. |
These methods need to be refactored to prevent extra calls to the database to retrieve a Consumer. Within the ConsumerResouce.java Class, getConsumer(uuid): calls the method consumerCurator.verifyAndLookupConsumer(uuid) to retrieve a Consumer. The method then proceeds to check the consumer object for imminent certificate expiration in the next 90 days or less. If it discovers certs are to expire in 90 days or less the method then calls: regenerateIdentityCertificates(uuid) the regenerateIdentityCertificates(uuid) method is not a utility method, but instead an endpoint definition that takes a uuid as an argument rather then taking a consumer object as the argument so of course the method calls: consumerCurator.verifyAndLookupConsumer(uuid) to get the consumer that the method the calling method (getConsumer) already has creating additional calls to the db for no gain whatsoever. In addition: consumerCurator.verifyAndLookupConsumer(uuid) verifies nothing. Why its name implies it does.... I suggest that the described code should be refactored as follows: public Consumer GetConsumer(..., String uuid){ Consumer consumer lookupConsumer(); // rename the verifyAndLookupConsumer // remove this line, you can never get here because the // verifyAndLookupConsumer(uuid) checks for null and throws an exception // if it finds one. Besides the next block makes it moot if (consumer != null) // move the cert check code to the consumer class so that certs // are checked every time the Consumer class is constructed. This was the consumer // class is always verified at construction. That way all rules for what is // a valid consumer are stored and validated in the consumer Class if (consumer.updateCertsRequired()) { this.updateCerts(consumer); } // enrich with subscription data consumer.setCanActivate(subAdapter.canActivateSubscription(consumer)); // enrich with installed product data addDataToInstalledProducts(consumer); return verifiedConsumer; } public Consumer regenerateIdentityCertificates(..., String uuid) { Consumer consumer lookupConsumer(); if (consumer.updateCertsRequired()) { this.updateCerts(consumer); } } private updateCerts(Consumer consumer){ // and so on and so forth }