diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2012-01-19 12:07:55 +0000 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2012-01-19 12:07:55 +0000 |
commit | 45e3ecda924473817a22e88b25b24fb770b5029c (patch) | |
tree | 5b9ca8f7c200e72e818f9ad91f6e1e7ef041e6d8 | |
parent | 69a2ea41c7c723ba11690ee6ed148cda012f8358 (diff) |
Always show the right search snippet. Fixes #352.
-rw-r--r-- | app/models/info_request_event.rb | 22 | ||||
-rw-r--r-- | spec/models/info_request_event_spec.rb | 7 |
2 files changed, 28 insertions, 1 deletions
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index e99a0ae2f..99f34cf9e 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -190,6 +190,26 @@ class InfoRequestEvent < ActiveRecord::Base return message end + def get_clipped_response_efficiently + # XXX this ugly code is an attempt to not always load all the + # columns for an incoming message, which can be *very* large + # (due to all the cached text). We care particularly in this + # case because it's called for every search result on a page + # (to show the search snippet). Actually, we should review if we + # need all this data to be cached in the database at all, and + # then we won't need this horrid workaround. + message = self.incoming_message_selective_columns("cached_attachment_text_clipped, cached_main_body_text_folded") + clipped_body = message.cached_main_body_text_folded + clipped_attachment = message.cached_attachment_text_clipped + if clipped_body.nil? || clipped_attachment.nil? + # we're going to have to load it anyway + text = self.incoming_message.get_text_for_indexing_clipped + else + text = clipped_body.gsub("FOLDED_QUOTED_SECTION", " ").strip + "\n\n" + clipped_attachment + end + return text + "\n\n" + end + # clipped = true - means return shorter text. It is used for snippets fore # performance reasons. Xapian will take the full text. def search_text_main(clipped = false) @@ -200,7 +220,7 @@ class InfoRequestEvent < ActiveRecord::Base text = text + self.outgoing_message.get_text_for_indexing + "\n\n" elsif self.event_type == 'response' if clipped - text = text + self.incoming_message_selective_columns("cached_attachment_text_clipped").cached_attachment_text_clipped + "\n\n" + text = text + self.get_clipped_response_efficiently else text = text + self.incoming_message.get_text_for_indexing_full + "\n\n" end diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 5423b8da8..63c859007 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -73,6 +73,13 @@ describe InfoRequestEvent do event.search_text_main.strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango" end + it 'should get clipped text for incoming messages, and cache it too' do + event = info_request_events(:useless_incoming_message_event) + event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded.should == nil + event.search_text_main(true).strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango" + event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded.should_not == nil + end + end |