liquid_feedback_frontend
changeset 549:42d070777353
Optimized fetching of calculated state_time_left attribute of issue
author | bsw |
---|---|
date | Tue May 29 20:52:20 2012 +0200 (2012-05-29) |
parents | 8af806af86a0 |
children | 65ddf5998458 |
files | model/issue.lua |
line diff
1.1 --- a/model/issue.lua Tue May 29 20:45:58 2012 +0200 1.2 +++ b/model/issue.lua Tue May 29 20:52:20 2012 +0200 1.3 @@ -1,6 +1,14 @@ 1.4 Issue = mondelefant.new_class() 1.5 Issue.table = 'issue' 1.6 1.7 +local new_selector = Issue.new_selector 1.8 + 1.9 +function Issue:new_selector() 1.10 + local selector = new_selector(self) 1.11 + selector:add_field("coalesce(issue.fully_frozen + issue.voting_time, issue.half_frozen + issue.verification_time, issue.accepted + issue.discussion_time, issue.created + issue.admission_time) - now()", "state_time_left") 1.12 + return selector 1.13 +end 1.14 + 1.15 Issue:add_reference{ 1.16 mode = 'm1', 1.17 to = "Area", 1.18 @@ -244,26 +252,6 @@ 1.19 return Issue:get_state_name_for_state(self.state) 1.20 end 1.21 1.22 -function Issue.object_get:state_time_left() 1.23 - local state = self.state 1.24 - local last_event_time 1.25 - local duration 1.26 - if state == "new" then 1.27 - last_event_time = self.created 1.28 - duration = self.admission_time 1.29 - elseif state == "accepted" then 1.30 - last_event_time = self.accepted 1.31 - duration = self.discussion_time 1.32 - elseif state == "frozen" then 1.33 - last_event_time = self.half_frozen 1.34 - duration = self.verification_time 1.35 - elseif state == "voting" then 1.36 - last_event_time = self.fully_frozen 1.37 - duration = self.voting_time 1.38 - end 1.39 - return db:query{ "SELECT ?::timestamp + ?::interval - CURRENT_TIMESTAMP(0) as time_left", last_event_time, duration }[1].time_left 1.40 -end 1.41 - 1.42 function Issue.object_get:next_states() 1.43 local state = self.state 1.44 local next_states