diff options
| author | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-11-27 14:53:12 +0200 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-11-27 14:53:12 +0200 |
| commit | 8ad1f8a4741522700dc7634e22ae946bbec2c845 (patch) | |
| tree | 7eebbfdc2acdc9622c010a45b3dd4cac9690a5b2 /app | |
| parent | fb8f05ee165b4da8aec0e4adf48992a86052ab04 (diff) | |
| download | gitlab-ce-8ad1f8a4741522700dc7634e22ae946bbec2c845.tar.gz | |
activities page caching
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/projects_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/project.rb | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a11ad08dc65..ee5f731e992 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -67,7 +67,7 @@ class ProjectsController < ApplicationController def show return render "projects/empty" unless @project.repo_exists? limit = (params[:limit] || 20).to_i - @activities = @project.updates(limit) + @activities = @project.cached_updates(limit) end # diff --git a/app/models/project.rb b/app/models/project.rb index 09c91fbd9ed..7998979d0d8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -143,6 +143,23 @@ class Project < ActiveRecord::Base last_activity.try(:created_at) end + # Get project updates from cache + # or calculate. + def cached_updates(limit, expire = 2.minutes) + activities_key = "project_#{id}_activities" + cached_activities = Rails.cache.read(activities_key) + if cached_activities + activities = cached_activities + else + activities = updates(limit) + Rails.cache.write(activities_key, activities, :expires_in => 60.seconds) + end + + activities + end + + # Get 20 events for project like + # commits, issues or notes def updates(n = 3) [ fresh_commits(n), |
