diff options
author | Gareth Rees <gareth@mysociety.org> | 2015-05-05 18:16:21 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2015-05-07 15:53:14 +0100 |
commit | 44be6f9014728c83adbc582baaba29c231365643 (patch) | |
tree | 8d1ddb1016509630a87d3ea9d742d5bae330bfea /app/models/info_request.rb | |
parent | 8068b389a0c3118eeb13148021bd064b9226a9e3 (diff) |
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)
Diffstat (limited to 'app/models/info_request.rb')
-rw-r--r-- | app/models/info_request.rb | 9 |
1 files changed, 9 insertions, 0 deletions
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 |