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

Fix error when viewing timelines in Optimize-Bottlenecks in IE #3529

Merged

Conversation

bmclaughlin
Copy link
Contributor

@epwinchell
Copy link
Contributor

@dclarizio Fix verified in IE9

@dclarizio
Copy link

@bmclaughlin Can we try to consolidate the duplicated code into a common method? Thx, Dan

@bmclaughlin
Copy link
Contributor Author

@tenderlove
Copy link
Contributor

Yes, we should definitely dry these up. Are they exactly the same? Just at a glance they look very similar. We should extract a function with the similar things, then extract the different bits. Sorry, that's a little vague, but essentially we should use the Extract Method technique a couple times. I can show you a patch to get you started if that helps!

@bmclaughlin
Copy link
Contributor Author

Not exactly the same, I found a one line difference that will be easily solved with one parameter. I wasn't sure where the best home for the extracted method would be (application helper or application controller?)?

@tenderlove
Copy link
Contributor

@bmclaughlin well it looks like this method creates XML that is only to do with VM instances. I would either move it to a VM related model, or a VM related presenter ("presenter" being code word for "plain old ruby object"). If we don't have a VM related presenter, I don't see why we shouldn't add one! :)

@bmclaughlin bmclaughlin force-pushed the optimize-bottlenecks-timeline-error branch from 3af69c2 to bbfbe7d Compare July 24, 2015 20:24
@@ -0,0 +1,12 @@
class VmPresenter
def initialize(controller, session)
@controller = controller
Copy link
Member

Choose a reason for hiding this comment

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

Why do we pass in the controller into this class if we do not use it? Is that some sort of pattern for presenters?

Copy link
Member

Choose a reason for hiding this comment

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

In reading here and here and here, this object should be initialized with a Vm, but instead, is getting a controller and session. It is not using the controller and I don't think it should be using the session. What does session[:tl_xml_blob_id] represent?

@tenderlove @matthewd @Fryguy Please comment on how we should use Presenters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed removing the passed in controller when refactoring the original code, thanks for catching that. The original code also made use of a Vm but that turned out to be dead code and was removed. Now in hindsight I see that I can pass the session value directly to the function as well. I'll make these changes momentarily.

Copy link
Contributor

Choose a reason for hiding this comment

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

Having been reduced to "get the thing from the DB object", this is no longer feeling like the place to have a presenter discussion, to me. Let's just inline the BinaryBlob.find back into the callers.

@bmclaughlin bmclaughlin force-pushed the optimize-bottlenecks-timeline-error branch from bbfbe7d to 66780cc Compare July 27, 2015 13:17
@dclarizio
Copy link

@bmclaughlin need to correct the failing spec.

@bmclaughlin bmclaughlin force-pushed the optimize-bottlenecks-timeline-error branch from 66780cc to df9b85d Compare July 27, 2015 20:55
@bmclaughlin
Copy link
Contributor Author

@chessbyte @Fryguy @dclarizio @matthewd, recommended changes implemented, please review.

@matthewd
Copy link
Contributor

if session[:tl_xml_blob_id] != nil should probably be spelled if session[:tl_xml_blob_id]

... but is it even useful? AFAICS, if it's not true, we'll fail to render, and (given there's no corresponding view) still end up with an error either way. So I think we can just lose it.

@matthewd
Copy link
Contributor

Err, we seem to have lost a destroy... was that deliberate?

@dclarizio
Copy link

@bmclaughlin Travis failure, seems a spec still has the CamelCased route in it.

@bmclaughlin
Copy link
Contributor Author

@matthewd, I agree on the nil check, and I lost the destroy on purpose as BinaryBlob is no longer being instantiated to a variable.

@dclarizio, fixed that pesky spec.

@chessbyte
Copy link
Member

@bmclaughlin the destroy removes the row from the database. Not sure I am following your explanation of why it was removed. (cc @matthewd)

@bmclaughlin
Copy link
Contributor Author

@chessbyte, apologies, thought that was destroying the object in memory. Need more coffee. Patch coming momentarily!

@chessbyte
Copy link
Member

Patch coming momentarily!

bump @bmclaughlin

@bmclaughlin
Copy link
Contributor Author

@chessbyte, 'Momentarily' became slightly longer due to a double rendering issue between rendering the view and rendering the xml for IE.

@bmclaughlin bmclaughlin force-pushed the optimize-bottlenecks-timeline-error branch 2 times, most recently from 8ab1097 to ee9c710 Compare August 3, 2015 20:35
@bmclaughlin
Copy link
Contributor Author

@chessbyte, @dclarizio this should be ready when travis finishes.

@chessbyte
Copy link
Member

@bmclaughlin there still seems to be code duplication between the new multiple timeline_data methods. Will that be refactored at some point via a new PR?

@chessbyte
Copy link
Member

@tenderlove @Fryguy @matthewd what is the best way to refactor the duplicate timeline_data methods? Is it via mixin, concern or some other technique/pattern?

if session[:tl_xml_blob_id] != nil
blob = BinaryBlob.find(session[:tl_xml_blob_id])
render :xml=>blob.binary
def timeline_data
Copy link
Member

Choose a reason for hiding this comment

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

If this timeline_data method is in ApplicationController, why do we need the duplicate methods in subclassed controllers (DashboardController and MiqCapacityController)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. Though, as it's apparently only used by three routes, I think I'd rather reduce the massive ApplicationController surface area by one method, and move it to whichever third controller is currently actually capable of getting here.

@matthewd
Copy link
Contributor

matthewd commented Aug 3, 2015

... but is it even useful? AFAICS, if it's not true, we'll fail to render, and (given there's no corresponding view) still end up with an error either way. So I think we can just lose it.

@matthewd
Copy link
Contributor

matthewd commented Aug 3, 2015

@chessbyte I don't think there's enough code there to duplicate, to warrant extraction. Especially if my above allegation is true.

- DRY'd and refactored getTLdata method
- added additional routing specs
- Fixed double render issue caused by partial
_bottlenecks_tl_detail.html.haml being rendered directly as
well as indirectly via _bottlenecks_tabs.html.haml

https://bugzilla.redhat.com/show_bug.cgi?id=1234588
@bmclaughlin bmclaughlin force-pushed the optimize-bottlenecks-timeline-error branch from ee9c710 to 2941dc7 Compare August 4, 2015 17:27
@bmclaughlin
Copy link
Contributor Author

@chessbyte, @matthewd Originally the miq_capacity_controller was throwing errors when trying to access the copy of timeline_data in application controller, however that seems to have been due to an intervening bug and the duplicate code is now properly DRY'd out as well as the suggested optimizations implemented. And I squashed the commits.

@miq-bot
Copy link
Member

miq-bot commented Aug 4, 2015

Checked commit bmclaughlin@2941dc7 with rubocop 0.32.1 and haml-lint 0.13.0
6 files checked, 0 offenses detected
Everything looks good. 🍰

@chessbyte
Copy link
Member

@bmclaughlin Nice and DRY! Waiting for Travis to go green before merging.

chessbyte added a commit that referenced this pull request Aug 4, 2015
…ne-error

Fix error when viewing timelines in Optimize-Bottlenecks in IE
@chessbyte chessbyte merged commit 4310a54 into ManageIQ:master Aug 4, 2015
@chessbyte chessbyte added this to the Sprint 28 Ending August 24, 2015 milestone Aug 4, 2015
@bmclaughlin bmclaughlin deleted the optimize-bottlenecks-timeline-error branch August 4, 2015 18:11
@matthewd
Copy link
Contributor

matthewd commented Aug 4, 2015

@bmclaughlin I'm still missing an answer to #3529 (comment)... I don't understand what the two return lines are gaining us: won't we still just get an error?

@bmclaughlin
Copy link
Contributor Author

@matthewd I agree, we will still just get an error. Would you like me to remove those lines in a quick follow-up PR?

@matthewd
Copy link
Contributor

matthewd commented Aug 4, 2015

Yeah, let's kill those two, and switch to find instead of find_by_id. 3 lines is better than 5 😄

(and while I'd generally favour find over find_by_id anyway, in any situation where we're not explicitly planning to handle a nil return... I think using find should convert both those error conditions to 404s, which is a nice bonus)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants