Commit 0a7c58530c7ca5c417e1353072411f1c523425d2

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent e5dba6d0

ActionItem991: added pagination and cache to communities

app/controllers/public/profile_controller.rb
... ... @@ -20,7 +20,9 @@ class ProfileController < PublicController
20 20 end
21 21  
22 22 def communities
23   - @communities = profile.communities
  23 + if is_cache_expired?(profile.communities_cache_key(params))
  24 + @communities = profile.communities.paginate(:per_page => per_page, :page => params[:npage])
  25 + end
24 26 end
25 27  
26 28 def enterprises
... ...
app/models/community.rb
... ... @@ -44,4 +44,8 @@ class Community < Organization
44 44 def news(limit = 30, highlight = false)
45 45 recent_documents(limit, ["articles.type != ? AND articles.highlighted = ?", 'Folder', highlight])
46 46 end
  47 +
  48 + def blocks_to_expire_cache
  49 + [MembersBlock]
  50 + end
47 51 end
... ...
app/views/profile/communities.rhtml
... ... @@ -3,11 +3,17 @@
3 3  
4 4 <h1><%= _("%s's communities") % profile.name %></h1>
5 5  
6   -<ul class='profile-list'>
7   -<% @communities.each do |community| %>
8   - <li><%= profile_image_link(community)%></li>
  6 +<% cache(profile.communities_cache_key(params)) do %>
  7 + <ul class='profile-list'>
  8 + <% @communities.each do |community| %>
  9 + <li><%= profile_image_link(community)%></li>
  10 + <% end %>
  11 + </ul>
  12 +
  13 + <div id='pagination-profiles'>
  14 + <%= pagination_links @communities, :param_name => 'npage' %>
  15 + </div>
9 16 <% end %>
10   -</ul>
11 17  
12 18 <% button_bar do %>
13 19 <%= button :back, _('Go back'), { :controller => 'profile' },
... ...