-
Notifications
You must be signed in to change notification settings - Fork 937
Improve performance of Message#find_attachment #825
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
base: master
Are you sure you want to change the base?
Conversation
- Don't trigger exceptions for flow control. - Retrieve each header only once (at most).
lib/mail/message.rb
Outdated
end | ||
|
||
content_location_header = header[:content_location] | ||
if content_location_header && (filename = content_location_header.location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
def find_attachment_filename
try_to_call(header[:content_type], :filename) ||
try_to_call(header[:content_disposition], :filename) ||
try_to_call(header[:content_location], :location)
end
def try_to_call(object, method)
object && object.send(method)
end
@grosser cleaned up the duplication in |
lib/mail/message.rb
Outdated
field.location | ||
when ContentTypeField, ContentDispositionField | ||
field.filename | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else raise ArgumentError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in principle, but it would be a change in behavior. I'd rather handle that separately.
Is there a benchmark you used that we can run to test against regressions? |
@bf4 I don't have anything that's easily extractable, I was profiling an application. I agree a benchmark suite would be really useful. |
This is faster because we,
The exceptions this was throwing were particularly expensive for us on jruby. This change cut our mail processing time in half for a particular task.
The tests are passing with this change but it's possible that the
rescue
s in the previous code were catching other exceptions that will now bubble up. We could add arescue
tofind_attachment_filename
to catch those.