aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/info_request_event.rb22
-rw-r--r--app/views/request/_request_listing_via_event.rhtml2
-rw-r--r--spec/models/info_request_event_spec.rb5
3 files changed, 23 insertions, 6 deletions
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 8b7b9ebe4..e99a0ae2f 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -109,7 +109,7 @@ class InfoRequestEvent < ActiveRecord::Base
[ :tags, 'U', "tag" ]
],
:if => :indexed_by_search?,
- :eager_load => [ :incoming_message, :outgoing_message, :comment, { :info_request => [ :user, :public_body, :censor_rules ] } ]
+ :eager_load => [ :outgoing_message, :comment, { :info_request => [ :user, :public_body, :censor_rules ] } ]
def requested_by
self.info_request.user.url_name
@@ -176,7 +176,21 @@ class InfoRequestEvent < ActiveRecord::Base
# format it here as no datetime support in Xapian's value ranges
return self.created_at.strftime("%Y%m%d%H%M%S")
end
- # clipped = true - means return shorter text. It is used for snippets for
+
+ def incoming_message_selective_columns(fields)
+ message = IncomingMessage.find(:all,
+ :select => fields + ", incoming_messages.info_request_id",
+ :joins => "INNER JOIN info_request_events ON incoming_messages.id = incoming_message_id ",
+ :conditions => "info_request_events.id = #{self.id}"
+ )
+ message = message[0]
+ if !message.nil?
+ message.info_request = InfoRequest.find(message.info_request_id)
+ end
+ return message
+ 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)
text = ''
@@ -186,7 +200,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.get_text_for_indexing_clipped + "\n\n"
+ text = text + self.incoming_message_selective_columns("cached_attachment_text_clipped").cached_attachment_text_clipped + "\n\n"
else
text = text + self.incoming_message.get_text_for_indexing_full + "\n\n"
end
@@ -296,7 +310,7 @@ class InfoRequestEvent < ActiveRecord::Base
end
- def is_incoming_message?() not self.incoming_message.nil? end
+ def is_incoming_message?() not self.incoming_message_selective_columns("incoming_messages.id").nil? end
def is_outgoing_message?() not self.outgoing_message.nil? end
def is_comment?() not self.comment.nil? end
diff --git a/app/views/request/_request_listing_via_event.rhtml b/app/views/request/_request_listing_via_event.rhtml
index e247163a3..7a211ed88 100644
--- a/app/views/request/_request_listing_via_event.rhtml
+++ b/app/views/request/_request_listing_via_event.rhtml
@@ -6,7 +6,7 @@ end %>
<div class="request_left">
<span class="head">
<% if event.is_incoming_message? %>
- <%= link_to highlight_words(info_request.title, @highlight_words), incoming_message_url(event.incoming_message) %>
+ <%= link_to highlight_words(info_request.title, @highlight_words), incoming_message_url(event.incoming_message_selective_columns("incoming_messages.id")) %>
<% elsif event.is_outgoing_message? and event.event_type == 'followup_sent' %>
<%= link_to highlight_words(info_request.title, @highlight_words), outgoing_message_url(event.outgoing_message) %>
<% elsif event.is_comment? %>
diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb
index 3229284cc..5423b8da8 100644
--- a/spec/models/info_request_event_spec.rb
+++ b/spec/models/info_request_event_spec.rb
@@ -29,7 +29,8 @@ describe InfoRequestEvent do
describe "should know" do
it "that it's an incoming message" do
- event = InfoRequestEvent.new(:incoming_message => mock_model(IncomingMessage))
+ event = InfoRequestEvent.new()
+ event.stub!(:incoming_message_selective_columns).and_return(1)
event.is_incoming_message?.should be_true
event.is_outgoing_message?.should be_false
event.is_comment?.should be_false
@@ -37,6 +38,7 @@ describe InfoRequestEvent do
it "that it's an outgoing message" do
event = InfoRequestEvent.new(:outgoing_message => mock_model(OutgoingMessage))
+ event.id = 1
event.is_incoming_message?.should be_false
event.is_outgoing_message?.should be_true
event.is_comment?.should be_false
@@ -44,6 +46,7 @@ describe InfoRequestEvent do
it "that it's a comment" do
event = InfoRequestEvent.new(:comment => mock_model(Comment))
+ event.id = 1
event.is_incoming_message?.should be_false
event.is_outgoing_message?.should be_false
event.is_comment?.should be_true