# HG changeset patch # User bsw # Date 1339779643 -7200 # Node ID c1dc3b14a4f3eec953ea4021b42938dc9c233cfe # Parent 65ddf59984582a9d095f1c5bd25a6aa805b7b737 Initiative and initiative member_info preloading diff -r 65ddf5998458 -r c1dc3b14a4f3 app/main/delegation/_info.lua --- a/app/main/delegation/_info.lua Tue May 29 20:52:49 2012 +0200 +++ b/app/main/delegation/_info.lua Fri Jun 15 19:00:43 2012 +0200 @@ -25,7 +25,9 @@ end if issue then - info = issue.member_info + if app.session.member_id then + info = issue.member_info + end delegation_text = _"Delegate issue" end @@ -185,4 +187,4 @@ } -end \ No newline at end of file +end diff -r 65ddf5998458 -r c1dc3b14a4f3 app/main/delegation/show.lua --- a/app/main/delegation/show.lua Tue May 29 20:52:49 2012 +0200 +++ b/app/main/delegation/show.lua Fri Jun 15 19:00:43 2012 +0200 @@ -24,7 +24,7 @@ local issue = Issue:by_id(param.get("issue_id", atom.integer)) if issue then - issue:load_delegation_info_once_for_member_id(app.session.member_id) + issue:load("member_info", { member_id = app.session.member_id }) voting_right_unit_id = issue.area.unit_id slot.put_into("title", encode.html(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name))) util.help("delegation.new.issue") diff -r 65ddf5998458 -r c1dc3b14a4f3 app/main/initiative/_list.lua --- a/app/main/initiative/_list.lua Tue May 29 20:52:49 2012 +0200 +++ b/app/main/initiative/_list.lua Fri Jun 15 19:00:43 2012 +0200 @@ -1,40 +1,24 @@ local issue = param.get("issue", "table") -local initiatives_selector = param.get("initiatives_selector", "table") +local initiatives = issue.initiatives local highlight_initiative = param.get("highlight_initiative", "table") local for_member = param.get("for_member", "table") or app.session.member -initiatives_selector - :join("issue", nil, "issue.id = initiative.issue_id") - -if app.session.member_id then - initiatives_selector - :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ? AND _initiator.accepted", for_member.id } ) - :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", for_member.id} ) - :left_join("delegating_interest_snapshot", "_delegating_interest_snapshot", { "_delegating_interest_snapshot.issue_id = initiative.issue_id AND _delegating_interest_snapshot.member_id = ? AND _delegating_interest_snapshot.event = issue.latest_snapshot_event", for_member.id} ) - :left_join("direct_supporter_snapshot", "_direct_supporter_snapshot", "_direct_supporter_snapshot.initiative_id = initiative.id AND _direct_supporter_snapshot.member_id = _delegating_interest_snapshot.delegate_member_ids[array_upper(_delegating_interest_snapshot.delegate_member_ids, 1)] AND _direct_supporter_snapshot.event = issue.latest_snapshot_event") - - :add_field("(_initiator.member_id NOTNULL)", "is_initiator") - :add_field({"(_supporter.member_id NOTNULL) AND NOT EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", for_member.id }, "is_supporter") - :add_field({"EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", for_member.id }, "is_potential_supporter") - - :add_field("_direct_supporter_snapshot.member_id NOTNULL", "is_supporter_via_delegation") -end - -initiatives_selector:add_order_by("initiative.rank, initiative.supporter_count DESC, initiative.id") - -local initiatives_count = initiatives_selector:count() - local limit = param.get("limit", atom.number) local more_initiatives_count if limit then - if initiatives_count > limit then - more_initiatives_count = initiatives_count - limit + if #initiatives > limit then + more_initiatives_count = #initiatives - limit end - initiatives_selector:limit(limit) + initiatives = {} + for i, initiative in ipairs(issue.initiatives) do + if i <= limit then + initiatives[#initiatives+1] = initiative + end + end end local issue = param.get("issue", "table") @@ -46,38 +30,30 @@ ui.add_partial_param_names{ name } -ui.paginate{ - name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil, - selector = initiatives_selector, - per_page = param.get("per_page", atom.number) or limit or 25, - content = function() - local initiatives = initiatives_selector:exec() - if highlight_initiative then - local highlight_initiative_found - for i, initiative in ipairs(initiatives) do - if initiative.id == highlight_initiative.id then - highhighlight_initiative_found = true - end - end - if not highhighlight_initiative_found then - initiatives[#initiatives+1] = highlight_initiative - if more_initiatives_count then - more_initiatives_count = more_initiatives_count - 1 - end - end - end - for i, initiative in ipairs(initiatives) do - execute.view{ - module = "initiative", - view = "_list_element", - params = { - initiative = initiative, - selected = highlight_initiative and highlight_initiative.id == initiative.id or nil, - } - } +if highlight_initiative then + local highlight_initiative_found + for i, initiative in ipairs(initiatives) do + if initiative.id == highlight_initiative.id then + highhighlight_initiative_found = true end end -} + if not highhighlight_initiative_found then + initiatives[#initiatives+1] = highlight_initiative + if more_initiatives_count then + more_initiatives_count = more_initiatives_count - 1 + end + end +end +for i, initiative in ipairs(initiatives) do + execute.view{ + module = "initiative", + view = "_list_element", + params = { + initiative = initiative, + selected = highlight_initiative and highlight_initiative.id == initiative.id or nil, + } + } +end if more_initiatives_count and more_initiatives_count > 0 then local text diff -r 65ddf5998458 -r c1dc3b14a4f3 app/main/initiative/_list_element.lua --- a/app/main/initiative/_list_element.lua Tue May 29 20:52:49 2012 +0200 +++ b/app/main/initiative/_list_element.lua Fri Jun 15 19:00:43 2012 +0200 @@ -59,30 +59,40 @@ end } ui.container{ attr = { class = "interest" }, content = function() - if initiative.is_initiator then + if initiative.member_info.initiated then local label = _"You are initiator of this initiative" ui.image{ attr = { alt = label, title = label }, static = "icons/16/user_edit.png" } - elseif initiative.is_supporter then - local label = _"You are supporter of this initiative" - ui.image{ - attr = { alt = label, title = label }, - static = "icons/16/thumb_up_green.png" - } - elseif initiative.is_potential_supporter then - local label = _"You are potentially supporter of this initiative" - ui.image{ - attr = { alt = label, title = label }, - static = "icons/16/thumb_up.png" - } - elseif initiative.is_supporter_via_delegation then - local label = _"You are supporter of this initiative via delegation" - ui.image{ - attr = { alt = label, title = label }, - static = "icons/16/thumb_up_green.png" - } + elseif initiative.member_info.directly_supported then + if initiative.member_info.satisfied then + local label = _"You are supporter of this initiative" + ui.image{ + attr = { alt = label, title = label }, + static = "icons/16/thumb_up_green.png" + } + else + local label = _"You are potential supporter of this initiative" + ui.image{ + attr = { alt = label, title = label }, + static = "icons/16/thumb_up.png" + } + end + elseif initiative.member_info.supported then + if initiative.member_info.satisfied then + local label = _"You are supporter of this initiative via delegation" + ui.image{ + attr = { alt = label, title = label }, + static = "icons/16/thumb_up_green_arrow.png" + } + else + local label = _"You are potential supporter of this initiative via delegation" + ui.image{ + attr = { alt = label, title = label }, + static = "icons/16/thumb_up_arrow.png" + } + end end end } diff -r 65ddf5998458 -r c1dc3b14a4f3 app/main/interest/_show_box.lua --- a/app/main/interest/_show_box.lua Tue May 29 20:52:49 2012 +0200 +++ b/app/main/interest/_show_box.lua Fri Jun 15 19:00:43 2012 +0200 @@ -2,10 +2,7 @@ local issue = param.get("issue", "table") local initiative = param.get("initiative", "table") -local interest = Interest:by_pk(issue.id, app.session.member.id) -local membership = Membership:by_pk(issue.area_id, app.session.member_id) - -if interest then +if issue.member_info.own_participation then if issue.closed then ui.tag{ content = _"You were interested" } diff -r 65ddf5998458 -r c1dc3b14a4f3 app/main/issue/_list.lua --- a/app/main/issue/_list.lua Tue May 29 20:52:49 2012 +0200 +++ b/app/main/issue/_list.lua Fri Jun 15 19:00:43 2012 +0200 @@ -31,7 +31,7 @@ content = function() local highlight_string = param.get("highlight_string", "string") local issues = issues_selector:exec() - issues:load_everything_for_member_id(member.id) + issues:load_everything_for_member_id(member and member.id or nil) ui.container{ attr = { class = "issues" }, content = function() diff -r 65ddf5998458 -r c1dc3b14a4f3 app/main/issue/_show.lua --- a/app/main/issue/_show.lua Tue May 29 20:52:49 2012 +0200 +++ b/app/main/issue/_show.lua Fri Jun 15 19:00:43 2012 +0200 @@ -94,7 +94,7 @@ slot.put(" · ") end - if not issue.closed then + if not issue.closed and app.session.member_id then if issue.member_info.own_delegation_scope ~= "issue" then ui.link{ text = _"Delegate issue", module = "delegation", view = "show", params = { issue_id = issue.id } } else @@ -181,9 +181,8 @@ issue = issue, initiatives_selector = initiatives_selector, highlight_string = highlight_string, - per_page = initiative_limit, no_sort = true, - limit = initiative_limit, + limit = 5, for_member = for_member } } diff -r 65ddf5998458 -r c1dc3b14a4f3 model/initiative.lua --- a/model/initiative.lua Tue May 29 20:52:49 2012 +0200 +++ b/model/initiative.lua Fri Jun 15 19:00:43 2012 +0200 @@ -108,6 +108,75 @@ ref = 'supporting_members_snapshot' } +Initiative:add_reference{ + mode = "11", + to = mondelefant.class_prototype, + this_key = "id", + that_key = "initiative_id", + ref = "member_info", + back_ref = "initiative", + selector_generator = function(list, options) + assert(options.member_id, "member_id mandatory for member_info") + local ids = { sep = ", " } + local issue_ids = { sep = ", " } + for i, object in ipairs(list) do + local id = object.id + if id ~= nil then + ids[#ids+1] = {"?", id} + issue_ids[#issue_ids+1] = { "?", object.issue_id } + end + end + + local sub_selector = Issue:get_db_conn():new_selector() + if #ids == 0 then + return sub_selector:empty_list_mode() + end + sub_selector:from("issue") + sub_selector:add_field("issue.id", "issue_id") + sub_selector:add_field{ '(delegation_info(?, null, null, issue.id, ?)).*', options.member_id, options.trustee_id } + sub_selector:add_where{ 'issue.id IN ($)', issue_ids } + + local selector = Initiative:get_db_conn():new_selector() + selector:add_from("initiative") + selector:add_field("initiative.id", "initiative_id") + selector:join("issue", nil, "issue.id = initiative.issue_id") + selector:join(sub_selector, "delegation_info", "delegation_info.issue_id = issue.id") + selector:add_field("delegation_info.*") + + selector:left_join("supporter", nil, "supporter.initiative_id = initiative.id AND supporter.member_id = delegation_info.participating_member_id") + + selector:left_join("delegating_interest_snapshot", "delegating_interest_s", { "delegating_interest_s.event = issue.latest_snapshot_event AND delegating_interest_s.issue_id = issue.id AND delegating_interest_s.member_id = ?", options.member_id }) + + selector:left_join("direct_supporter_snapshot", "supporter_s", { "supporter_s.event = issue.latest_snapshot_event AND supporter_s.initiative_id = initiative.id AND (supporter_s.member_id = ? OR supporter_s.member_id = delegating_interest_s.delegate_member_ids[array_upper(delegating_interest_s.delegate_member_ids, 1)])", options.member_id }) + + selector:add_field("CASE WHEN issue.fully_frozen ISNULL AND issue.closed ISNULL THEN supporter.member_id NOTNULL ELSE supporter_s.member_id NOTNULL END", "supported") + selector:add_field({ "CASE WHEN issue.fully_frozen ISNULL AND issue.closed ISNULL THEN delegation_info.own_participation AND supporter.member_id NOTNULL ELSE supporter_s.member_id = ? END", options.member_id }, "directly_supported") + + selector:add_field("CASE WHEN issue.fully_frozen ISNULL AND issue.closed ISNULL THEN supporter.member_id NOTNULL AND NOT EXISTS(SELECT 1 FROM critical_opinion WHERE critical_opinion.initiative_id = initiative.id AND critical_opinion.member_id = delegation_info.participating_member_id) ELSE supporter_s.satisfied NOTNULL END", "satisfied") + + + --selector:add_field("", "informed") + selector:left_join("initiator", nil, { "initiator.initiative_id = initiative.id AND initiator.member_id = ? AND initiator.accepted", options.member_id }) + selector:add_field("initiator.member_id NOTNULL", "initiated") + + return selector + end +} + +function Initiative.list:load_everything_for_member_id(member_id) + if member_id then + self:load("member_info", { member_id = member_id }) + end +end + +function Initiative.object:load_everything_for_member_id(member_id) + if member_id then + self:load("member_info", { member_id = member_id }) + end +end + + + function Initiative:get_search_selector(search_string) return self:new_selector() diff -r 65ddf5998458 -r c1dc3b14a4f3 model/issue.lua --- a/model/issue.lua Tue May 29 20:52:49 2012 +0200 +++ b/model/issue.lua Fri Jun 15 19:00:43 2012 +0200 @@ -31,7 +31,8 @@ this_key = 'id', that_key = 'issue_id', ref = 'initiatives', - back_ref = 'issue' + back_ref = 'issue', + default_order = 'initiative.rank, initiative.supporter_count DESC, id' } Issue:add_reference{ @@ -159,14 +160,22 @@ local areas = self:load("area") areas:load("unit") self:load("policy") - self:load("member_info", { member_id = member_id }) + if member_id then + self:load("member_info", { member_id = member_id }) + end + local initiatives = self:load("initiatives") + initiatives:load_everything_for_member_id(member_id) end function Issue.object:load_everything_for_member_id(member_id) local areas = self:load("area") areas:load("unit") self:load("policy") - self:load("member_info", { member_id = member_id }) + if member_id then + self:load("member_info", { member_id = member_id }) + end + local initiatives = self:load("initiatives") + initiatives:load_everything_for_member_id(member_id) end function Issue:get_state_name_for_state(value) @@ -281,4 +290,4 @@ function Issue.object_get:etherpad_url() return config.etherpad.base_url .. "p/" .. config.etherpad.group_id .. "$Issue" .. self.id -end \ No newline at end of file +end diff -r 65ddf5998458 -r c1dc3b14a4f3 model/member.lua --- a/model/member.lua Tue May 29 20:52:49 2012 +0200 +++ b/model/member.lua Fri Jun 15 19:00:43 2012 +0200 @@ -488,9 +488,9 @@ :for_share() :exec() self.__units_with_voting_right_hash = {} - for i, privilege in ipairs(privileges) do - self.__units_with_voting_right_hash[privilege.unit_id] = true - end + for i, privilege in ipairs(privileges) do + self.__units_with_voting_right_hash[privilege.unit_id] = true + end end return self.__units_with_voting_right_hash[unit_id] and true or false end diff -r 65ddf5998458 -r c1dc3b14a4f3 static/icons/16/thumb_up_arrow.png Binary file static/icons/16/thumb_up_arrow.png has changed diff -r 65ddf5998458 -r c1dc3b14a4f3 static/icons/16/thumb_up_green_arrow.png Binary file static/icons/16/thumb_up_green_arrow.png has changed