docbrown/app/models/email_message.rb
Andy Zhao c9efc7a2b2 Fix repeated queries for reports (#835)
* Fix repeated queries for reports

* Load stylesheet once by moving into index

* Remove unused method

* Remove unused code again and update method

* Use better name for migration and add indices

* Use latest schema version oops

* Add missing column to query
2018-10-09 12:42:55 -04:00

15 lines
628 B
Ruby

class EmailMessage < Ahoy::Message
# So far this is mostly used to be compatible with administrate gem,
# which doesn't seem to play nicely with namespaces. But there could be other
# reasons to define behavior here, similar to how we use the Tag model.
def body_html_content
doctype_index = content.index("<!DOCTYPE")
closing_html_index = content.index("</html>") + 6
content[doctype_index..closing_html_index]
end
def self.find_for_reports(feedback_message_ids)
select(:to, :subject, :content, :utm_campaign, :feedback_message_id).
where(feedback_message_id: feedback_message_ids)
end
end