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

Stub mini-mime in for mime-types #14525

Merged
merged 1 commit into from
Jun 23, 2017

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented Mar 27, 2017

Uses a stub for the two mime-types methods used by rest-client and mail (the only dependencies of mime-types) and forwards them on to mini-mime. Should reduce the memory footprint from that gem... hopefully...

Before

before

After

after

For those stopping in (👋) , the links to the rest-client PR will provide some context to why this PR exists.

Links

@NickLaMuro NickLaMuro changed the title Stub mini-mime in for mime-types [WIP] Stub mini-mime in for mime-types Mar 27, 2017
@NickLaMuro
Copy link
Member Author

For the record, have not ran anything to confirm that this works as an interface, only that the application loads when this is in place. Further tests will need to be done before we even consider merging this.

end

def self.type_for filename
Array.wrap MiniMime.lookup_by_filename(filename)
Copy link
Member

@Fryguy Fryguy Mar 27, 2017

Choose a reason for hiding this comment

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

I think you need a .collect(&:content_type) here?

 Array.wrap(MiniMime.lookup_by_filename(filename).content_type)

Copy link
Member Author

Choose a reason for hiding this comment

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

@Fryguy Well, I was going off of this change:

https://github.com/rest-client/rest-client/pull/557/files#diff-3724e1adc91ded3d8e979d73f91f1b1eL915

So I don't think so, but maybe I read that diff wrong (it was Monday morning at the time of writing this code...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh... I think I see the error in my ways now...

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 think I was right the first time... see #14525 (comment)

@Fryguy
Copy link
Member

Fryguy commented Mar 27, 2017

@Fryguy
Copy link
Member

Fryguy commented Mar 27, 2017

Once this gets nailed down, this might be a good addition to the mini_mime gem. This way they have a workaround to intercepting mime/types in places where rest-client or mail can't be upgraded.

@NickLaMuro
Copy link
Member Author

Once this gets nailed down, this might be a good addition to the mini_mime gem. This way they have a workaround to intercepting mime/types in places where rest-client or mail can't be upgraded.

I agree, though I am not sure how we could do that from within the mini-mime gem itself. This works because we tricking bundler in that this is the dependency for mime-types, when really it is just a stub. I don't think we could do that with mini-mime alone, and the contribution would more be a README "howto" entry I think.

@NickLaMuro
Copy link
Member Author

NickLaMuro commented Mar 27, 2017

@NickLaMuro Also see this one: https://github.com/mikel/mail/pull/1060/files#diff-636a445469a465e4b5088a2b37b105b1L102

@Fryguy I think the way that is called, that is different, but I did see that one, which is why I was confused for a bit. But looking at this:

https://github.com/ManageIQ/manageiq/blob/master/app/models/filesystem.rb#L111-L118

Looks like I think returning a MIME::Type is what is expected, and a content_type should be fetched from that (FYI, .of is just an alias for .type_for).

@chessbyte chessbyte added the core label Mar 29, 2017
@blomquisg blomquisg removed their request for review May 4, 2017 19:35
@blomquisg
Copy link
Member

Booted myself from the reviewers list. Mime types are just not anything I feel I can give an up or down vote.

@miq-bot
Copy link
Member

miq-bot commented May 26, 2017

This pull request is not mergeable. Please rebase and repush.

@NickLaMuro NickLaMuro force-pushed the mini-mime-mime-types-stub branch from 09dffb6 to f2fd8c5 Compare June 6, 2017 16:20
@NickLaMuro NickLaMuro changed the title [WIP] Stub mini-mime in for mime-types Stub mini-mime in for mime-types Jun 6, 2017
@Fryguy
Copy link
Member

Fryguy commented Jun 14, 2017

@NickLaMuro Do you have any numbers for the memory/time savings? I thought they were in this thread, but i can't find them.

s.summary = "Stub mime-types repo that redirects to mini-mime"

s.add_dependency 'mini_mime', '>= 0.1.1'
end
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we can just make this a released gem somehow, but I can't think of how you would make the Gemfile work. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that was my thing too. We can't make this quack as a dependency that is resolvable using rubygems, and so the best we could do is move this into a git repo... but that even seems overkill.

Not completely opposed to the idea, though, hate adding another git gem to the repo... Either way, I would probably put some tests around it if we wanted to do that.

@NickLaMuro
Copy link
Member Author

@Fryguy Yeah, I feel like we might have talked about this in chat or something with the people involved, but it is around a 10MiB savings.

Regardless, will do a quick test before and after and add it to the top.

@NickLaMuro
Copy link
Member Author

NickLaMuro commented Jun 14, 2017

@Fryguy well, I have been testing for probably the past 20 min, and the results are varied enough where I don't think putting them here in full will help.

But the short version is what I have here is basically a 0.0MiB for the require "mime-types", and master is around 3MiB and up (depends on the mood I guess...).

@NickLaMuro NickLaMuro force-pushed the mini-mime-mime-types-stub branch from f2fd8c5 to 3879297 Compare June 14, 2017 19:41
@Fryguy
Copy link
Member

Fryguy commented Jun 14, 2017

@NickLaMuro Can you verify that with the change, that the UI classic repo still passes? I am concerned because UI classic still references capybara which, in turn, still uses the mime-types gem and I'm concerned that it will try to load the gem anyway, clobbering your changes.

Uses a stub for the two mime-types methods used by rest-client and mail
(the only dependencies of mime-types) and forwards them on to mini-mime.
Should reduce the memory footprint from that gem... hopefully...
@NickLaMuro
Copy link
Member Author

Said in a PM to @Fryguy, but I used this branch to run the test suite for manageiq-ui-classic, and everything passed in both suites except one test. That test failed only the first time (out of two), and it was a discrepancy in expected json keys, which doesn't point to an issue with this mime-types change.

@NickLaMuro NickLaMuro force-pushed the mini-mime-mime-types-stub branch from 3879297 to 8cfab3b Compare June 20, 2017 21:37
@miq-bot
Copy link
Member

miq-bot commented Jun 20, 2017

Checked commit NickLaMuro@8cfab3b with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 2 offenses detected

mime-types-redirector/lib/mime-types.rb

  • ❗ - Line 13, Col 7 - Style/Alias - Use alias instead of alias_method in a class body.
  • ❗ - Line 1, Col 1 - Style/FileName - The name of this source file (mime-types.rb) should use snake_case.

@Fryguy
Copy link
Member

Fryguy commented Jun 23, 2017

Looks good to me...merging, and then let's see how it plays out.

@Fryguy Fryguy merged commit bb244dc into ManageIQ:master Jun 23, 2017
@Fryguy Fryguy added this to the Sprint 64 Ending Jul 3, 2017 milestone Jun 23, 2017
@Fryguy
Copy link
Member

Fryguy commented Jun 23, 2017

@Fryguy
Copy link
Member

Fryguy commented Jun 26, 2017

@NickLaMuro I've opened discourse/mini_mime#6 to see if we can get this into mini_mime in some form, if they are willing to accept it.

@NickLaMuro
Copy link
Member Author

@Fryguy Thanks! I think having a more official solution is probably for the best.

@himdel
Copy link
Contributor

himdel commented Jun 29, 2017

Note this also seems to break running rspec foo.. in ui-classic in some cases.. (because of that bundler bug it would seem)...

The path /home/hkataria/dev/manageiq-ui-classic/mime-types-redirector does not
exist.

But making a symlink to that dir fixes that :)

@NickLaMuro
Copy link
Member Author

@himdel Do you have a link to what test was failing with this? I might see if there is another bug with bundler that I need to look into with this.

@NickLaMuro
Copy link
Member Author

Note this also seems to break running rspec foo.. in ui-classic in some cases.. (because of that bundler bug it would seem)...

As just a minor FYI, this only fixes the problem where bundle install followed by a bundle install --deployment doesn't work because of incorrect relative path resolution from a given root (basically, using the wrong root). I think there might be a different bug in which the root for the path is resolved incorrectly, and I might need to look into that.

@himdel
Copy link
Contributor

himdel commented Jun 30, 2017

@NickLaMuro It was not a specific test failing, it was not being able to run any specs via rspec. But.. it is possible it would have worked with bundle exec. Right now if I run it without, it actually complains that The path '/home/himdel/manageiq-ui-classic/spec/manageiq-ui-classic' does not exist. for some reason :).

EDIT:

And @martinpovolny just hit the manageiq-ui-classic/mime-types-redirector does not exist bug even when running bundle exec rspec ... in ui-classic.

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.

6 participants