Commit 75f3fbe9f87422099aa1c6ec50c115bde32275ba
Committed by
Diego Araújo
1 parent
973275c7
Exists in
colab
and in
2 other branches
Fix home page latest content cache efectiveness
There were instance variables filled by fetching the latest content every time, defeating the purpose of the fragment caches in the view. Replace them with helper methods, that also make the number of items visible in the view. Signed-off-by: otaviocv <otavio@deluqui.com.br>
Showing
2 changed files
with
15 additions
and
7 deletions
Show diff stats
app/controllers/home_controller.rb
1 | 1 | class HomeController < ApplicationController |
2 | - def index | |
3 | - @latest_projects = Project.latest(5) | |
4 | - @latest_repositories = Repository.latest(5) | |
5 | - @latest_configurations = KalibroConfiguration.latest(5) | |
2 | + helper_method :latest_projects, :latest_repositories, :latest_configurations | |
3 | + | |
4 | + def latest_projects(count) | |
5 | + Project.latest(count) | |
6 | + end | |
7 | + | |
8 | + def latest_repositories(count) | |
9 | + Repository.latest(count) | |
10 | + end | |
11 | + | |
12 | + def latest_configurations(count) | |
13 | + KalibroConfiguration.latest(count) | |
6 | 14 | end |
7 | 15 | end | ... | ... |
app/views/home/index.html.erb
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | |
14 | 14 | <ul> |
15 | 15 | <% cache action_suffix: 'latest_projects' do %> |
16 | - <% @latest_projects.each do |project| %> | |
16 | + <% latest_projects(5).each do |project| %> | |
17 | 17 | <li><%= link_to(project.name, project_path(project.id)) %></li> |
18 | 18 | <% end %> |
19 | 19 | <% end %> |
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | |
25 | 25 | <ul> |
26 | 26 | <% cache action_suffix: 'latest_repositories' do %> |
27 | - <% @latest_repositories.each do |repository| %> | |
27 | + <% latest_repositories(5).each do |repository| %> | |
28 | 28 | <li><%= link_to(repository.name, repository_path(repository.id)) %></li> |
29 | 29 | <% end %> |
30 | 30 | <% end %> |
... | ... | @@ -35,7 +35,7 @@ |
35 | 35 | |
36 | 36 | <ul> |
37 | 37 | <% cache action_suffix: 'latest_configurations' do %> |
38 | - <% @latest_configurations.each do |configuration| %> | |
38 | + <% latest_configurations(5).each do |configuration| %> | |
39 | 39 | <li><%= link_to(configuration.name, kalibro_configuration_path(configuration.id)) %></li> |
40 | 40 | <% end %> |
41 | 41 | <% end %> | ... | ... |