Commit 20ce2db1f38a35763eef51cbfee547e84133c4d3
Committed by
Antonio Terceiro
1 parent
d9378c95
Exists in
master
and in
28 other branches
ActionItem1225: some performance improvements
* On sitemap, only top level articles are listed * Cache on list of environment tags * Cache on list of profile tags * Cache and pagination when listing environment articles with some tag * Cache and pagination when listing profile articles with some tag
Showing
8 changed files
with
50 additions
and
26 deletions
Show diff stats
app/controllers/public/profile_controller.rb
@@ -11,12 +11,18 @@ class ProfileController < PublicController | @@ -11,12 +11,18 @@ class ProfileController < PublicController | ||
11 | end | 11 | end |
12 | 12 | ||
13 | def tags | 13 | def tags |
14 | - @tags = profile.article_tags | 14 | + @tags_cache_key = "tags_profile_#{profile.id.to_s}" |
15 | + if is_cache_expired?(@tags_cache_key, true) | ||
16 | + @tags = profile.article_tags | ||
17 | + end | ||
15 | end | 18 | end |
16 | 19 | ||
17 | def tag | 20 | def tag |
18 | @tag = params[:id] | 21 | @tag = params[:id] |
19 | - @tagged = profile.find_tagged_with(@tag) | 22 | + @tag_cache_key = "tag_#{@tag.to_s.gsub(' ', '%20')}_#{profile.id.to_s}_page_#{params[:npage]}" |
23 | + if is_cache_expired?(@tag_cache_key, true) | ||
24 | + @tagged = profile.find_tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage]) | ||
25 | + end | ||
20 | end | 26 | end |
21 | 27 | ||
22 | def communities | 28 | def communities |
app/controllers/public/search_controller.rb
@@ -219,15 +219,21 @@ class SearchController < PublicController | @@ -219,15 +219,21 @@ class SearchController < PublicController | ||
219 | attr_reader :category | 219 | attr_reader :category |
220 | 220 | ||
221 | def tags | 221 | def tags |
222 | - @tags = environment.tags.inject({}) do |memo,tag| | ||
223 | - memo[tag.name] = tag.taggings.count | ||
224 | - memo | 222 | + @tags_cache_key = "tags_env_#{environment.id.to_s}" |
223 | + if is_cache_expired?(@tags_cache_key, true) | ||
224 | + @tags = environment.tags.inject({}) do |memo,tag| | ||
225 | + memo[tag.name] = tag.taggings.count | ||
226 | + memo | ||
227 | + end | ||
225 | end | 228 | end |
226 | end | 229 | end |
227 | 230 | ||
228 | def tag | 231 | def tag |
229 | @tag = environment.tags.find_by_name(params[:tag]) | 232 | @tag = environment.tags.find_by_name(params[:tag]) |
230 | - @tagged = environment.articles.find_tagged_with(@tag) | 233 | + @tag_cache_key = "tag_#{@tag.to_s.gsub(' ', '%20')}_env_#{environment.id.to_s}_page_#{params[:npage]}" |
234 | + if is_cache_expired?(@tag_cache_key, true) | ||
235 | + @tagged = environment.articles.find_tagged_with(@tag).paginate(:per_page => 10, :page => params[:npage]) | ||
236 | + end | ||
231 | end | 237 | end |
232 | 238 | ||
233 | ####################################################### | 239 | ####################################################### |
app/views/layouts/application-ng.rhtml
@@ -61,7 +61,7 @@ | @@ -61,7 +61,7 @@ | ||
61 | <%= link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', { :controller => 'admin_panel', :action => 'index' }, :id => "controlpanel", :title => _("Configure the environment")) %> | 61 | <%= link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', { :controller => 'admin_panel', :action => 'index' }, :id => "controlpanel", :title => _("Configure the environment")) %> |
62 | <% end %> | 62 | <% end %> |
63 | <% if (user.environment == environment) %> | 63 | <% if (user.environment == environment) %> |
64 | - <%= link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', user.admin_url, :id => "controlpanel", :title => _("Configure your personal account and content")) if (user.environment == environment) %> | 64 | + <%= link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', user.admin_url, :id => "controlpanel", :title => _("Configure your personal account and content")) %> |
65 | <% end %> | 65 | <% end %> |
66 | <%= link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system")) %> | 66 | <%= link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system")) %> |
67 | <% else %> | 67 | <% else %> |
app/views/profile/sitemap.rhtml
app/views/profile/tag.rhtml
1 | <h1><%= _('Content tagged with "%s"') % @tag %></h1> | 1 | <h1><%= _('Content tagged with "%s"') % @tag %></h1> |
2 | 2 | ||
3 | -<div class='search-tagged-items'> | ||
4 | - <ul> | ||
5 | - <% for doc in @tagged %> | ||
6 | - <li><%= link_to doc.title, doc.url %></li> | ||
7 | - <% end %> | ||
8 | - </ul> | ||
9 | -</div> | 3 | +<% cache_timeout(@tag_cache_key, 4.hour.from_now) do %> |
4 | + <div class='search-tagged-items'> | ||
5 | + <ul> | ||
6 | + <% for doc in @tagged %> | ||
7 | + <li><%= link_to doc.title, doc.url %></li> | ||
8 | + <% end %> | ||
9 | + </ul> | ||
10 | + </div> | ||
10 | 11 | ||
11 | -<div> | ||
12 | - <%= link_to _('See content tagged with "%s" in the entire site') % @tag, :controller => 'search', :action => 'tag', :tag => @tag %> | ||
13 | -</div> | 12 | + <%= pagination_links @tagged, :param_name => 'npage' %> |
13 | + | ||
14 | + <div> | ||
15 | + <%= link_to _('See content tagged with "%s" in the entire site') % @tag, :controller => 'search', :action => 'tag', :tag => @tag %> | ||
16 | + </div> | ||
17 | +<% end %> |
app/views/profile/tags.rhtml
1 | <h1><%= _("%s's tags") % @profile.name %></h1> | 1 | <h1><%= _("%s's tags") % @profile.name %></h1> |
2 | 2 | ||
3 | -<%= tag_cloud(@tags, :id, { :action => :tag}, {:show_count => true} ) %> | 3 | +<% cache_timeout(@tags_cache_key, 4.hour.from_now) do %> |
4 | + <%= tag_cloud(@tags, :id, { :action => :tag}, {:show_count => true} ) %> | ||
5 | +<% end %> |
app/views/search/tag.rhtml
@@ -6,9 +6,14 @@ | @@ -6,9 +6,14 @@ | ||
6 | <%= button('back', _('Back to tag cloud'), :action => 'tags') %> | 6 | <%= button('back', _('Back to tag cloud'), :action => 'tags') %> |
7 | <% end %> | 7 | <% end %> |
8 | 8 | ||
9 | -<div class='search-tagged-items'> | ||
10 | -<% @tagged.each do |hit| %> | ||
11 | - <%= render :partial => partial_for_class(hit.class), :object => hit %> | ||
12 | - <br style='clear: left;'/> | 9 | +<% cache_timeout(@tag_cache_key, 4.hour.from_now) do %> |
10 | + <div class='search-tagged-items'> | ||
11 | + <% @tagged.each do |hit| %> | ||
12 | + <%= render :partial => partial_for_class(hit.class), :object => hit %> | ||
13 | + <br style='clear: left;'/> | ||
14 | + <% end %> | ||
15 | + | ||
16 | + </div> | ||
17 | + <%= pagination_links @tagged, :param_name => 'npage' %> | ||
18 | + | ||
13 | <% end %> | 19 | <% end %> |
14 | -</div> |
app/views/search/tags.rhtml