activities page caching
This commit is contained in:
parent
fb8f05ee16
commit
8ad1f8a474
|
@ -67,7 +67,7 @@ class ProjectsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
return render "projects/empty" unless @project.repo_exists?
|
return render "projects/empty" unless @project.repo_exists?
|
||||||
limit = (params[:limit] || 20).to_i
|
limit = (params[:limit] || 20).to_i
|
||||||
@activities = @project.updates(limit)
|
@activities = @project.cached_updates(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -143,6 +143,23 @@ class Project < ActiveRecord::Base
|
||||||
last_activity.try(:created_at)
|
last_activity.try(:created_at)
|
||||||
end
|
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)
|
def updates(n = 3)
|
||||||
[
|
[
|
||||||
fresh_commits(n),
|
fresh_commits(n),
|
||||||
|
|
|
@ -37,7 +37,7 @@ Gitlab::Application.configure do
|
||||||
# config.logger = SyslogLogger.new
|
# config.logger = SyslogLogger.new
|
||||||
|
|
||||||
# Use a different cache store in production
|
# Use a different cache store in production
|
||||||
# config.cache_store = :mem_cache_store
|
config.cache_store = :memory_store
|
||||||
|
|
||||||
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
||||||
# config.action_controller.asset_host = "http://assets.example.com"
|
# config.action_controller.asset_host = "http://assets.example.com"
|
||||||
|
|
Loading…
Reference in a new issue