Commit 8ad1f8a4741522700dc7634e22ae946bbec2c845
1 parent
fb8f05ee
Exists in
master
and in
4 other branches
activities page caching
Showing
3 changed files
with
19 additions
and
2 deletions
Show diff stats
app/controllers/projects_controller.rb
| ... | ... | @@ -67,7 +67,7 @@ class ProjectsController < ApplicationController |
| 67 | 67 | def show |
| 68 | 68 | return render "projects/empty" unless @project.repo_exists? |
| 69 | 69 | limit = (params[:limit] || 20).to_i |
| 70 | - @activities = @project.updates(limit) | |
| 70 | + @activities = @project.cached_updates(limit) | |
| 71 | 71 | end |
| 72 | 72 | |
| 73 | 73 | # | ... | ... |
app/models/project.rb
| ... | ... | @@ -143,6 +143,23 @@ class Project < ActiveRecord::Base |
| 143 | 143 | last_activity.try(:created_at) |
| 144 | 144 | end |
| 145 | 145 | |
| 146 | + # Get project updates from cache | |
| 147 | + # or calculate. | |
| 148 | + def cached_updates(limit, expire = 2.minutes) | |
| 149 | + activities_key = "project_#{id}_activities" | |
| 150 | + cached_activities = Rails.cache.read(activities_key) | |
| 151 | + if cached_activities | |
| 152 | + activities = cached_activities | |
| 153 | + else | |
| 154 | + activities = updates(limit) | |
| 155 | + Rails.cache.write(activities_key, activities, :expires_in => 60.seconds) | |
| 156 | + end | |
| 157 | + | |
| 158 | + activities | |
| 159 | + end | |
| 160 | + | |
| 161 | + # Get 20 events for project like | |
| 162 | + # commits, issues or notes | |
| 146 | 163 | def updates(n = 3) |
| 147 | 164 | [ |
| 148 | 165 | fresh_commits(n), | ... | ... |
config/environments/production.rb
| ... | ... | @@ -37,7 +37,7 @@ Gitlab::Application.configure do |
| 37 | 37 | # config.logger = SyslogLogger.new |
| 38 | 38 | |
| 39 | 39 | # Use a different cache store in production |
| 40 | - # config.cache_store = :mem_cache_store | |
| 40 | + config.cache_store = :memory_store | |
| 41 | 41 | |
| 42 | 42 | # Enable serving of images, stylesheets, and JavaScripts from an asset server |
| 43 | 43 | # config.action_controller.asset_host = "http://assets.example.com" | ... | ... |