From 44be6f9014728c83adbc582baaba29c231365643 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 5 May 2015 18:16:21 +0100 Subject: Use existing attribute `last_event_time` is set as a result of calling `InfoRequest.find_in_state`. This commit adds an explicit accessor that converts it to a `DateTime` and uses it in the view, preventing an extra query for each `InfoRequest` in the result set. Before: Completed 200 OK in 14908.9ms (Views: 14625.3ms | ActiveRecord: 69.8ms) After: Completed 200 OK in 2481.0ms (Views: 2437.1ms | ActiveRecord: 5.2ms) --- app/models/info_request.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 0ca3a1279..b742dcc03 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1383,6 +1383,15 @@ public end end + # The DateTime of the last InfoRequestEvent belonging to the InfoRequest + # Only available if the last_event_time attribute has been set. This is + # currentlt only set through .find_in_state + # + # Returns a DateTime + def last_event_time + attributes['last_event_time'].try(:to_datetime) + end + private def set_defaults -- cgit v1.2.3 From 0b2b8f0c280777fc531ddfafc9df6dbab645ec49 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 6 May 2015 17:23:15 +0100 Subject: Use database attributes to find public_response_events user system total real old 1.070000 0.280000 1.350000 ( 1.657773) new 0.560000 0.120000 0.680000 ( 0.743485) --- app/models/info_request.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index b742dcc03..3ce89be3b 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -777,7 +777,14 @@ public end def public_response_events - self.info_request_events.select{|e| e.response? && e.incoming_message.all_can_view? } + condition = <<-SQL + info_request_events.event_type = ? + AND incoming_messages.prominence = ? + SQL + + info_request_events. + joins(:incoming_message). + where(condition, 'response', 'normal') end # The last public response is the default one people might want to reply to -- cgit v1.2.3