From 4c1538a9465304acc22502f12199d2e2b360cb81 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Wed, 6 Mar 2013 17:30:48 +0200
Subject: [PATCH] Use redis as cache storage. cache events

---
 Gemfile                           |  3 +++
 Gemfile.lock                      | 17 +++++++++++++++++
 app/views/events/_event.html.haml | 23 ++++++++++++-----------
 config/environments/production.rb |  2 +-
 4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/Gemfile b/Gemfile
index cf1617c316..3bdc3c9421 100644
--- a/Gemfile
+++ b/Gemfile
@@ -103,6 +103,9 @@ gem 'settingslogic'
 gem "foreman"
 gem "git"
 
+# Cache
+gem "redis-rails"
+
 group :assets do
   gem "sass-rails",   "~> 3.2.5"
   gem "coffee-rails", "~> 3.2.2"
diff --git a/Gemfile.lock b/Gemfile.lock
index 89882492b3..f31de0dfbb 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -329,8 +329,24 @@ GEM
       json (~> 1.4)
     redcarpet (2.2.2)
     redis (3.0.2)
+    redis-actionpack (3.2.3)
+      actionpack (~> 3.2.3)
+      redis-rack (~> 1.4.0)
+      redis-store (~> 1.1.0)
+    redis-activesupport (3.2.3)
+      activesupport (~> 3.2.3)
+      redis-store (~> 1.1.0)
     redis-namespace (1.2.1)
       redis (~> 3.0.0)
+    redis-rack (1.4.2)
+      rack (~> 1.4.1)
+      redis-store (~> 1.1.0)
+    redis-rails (3.2.3)
+      redis-actionpack (~> 3.2.3)
+      redis-activesupport (~> 3.2.3)
+      redis-store (~> 1.1.0)
+    redis-store (1.1.3)
+      redis (>= 2.2.0)
     request_store (1.0.5)
     rspec (2.12.0)
       rspec-core (~> 2.12.0)
@@ -504,6 +520,7 @@ DEPENDENCIES
   rb-fsevent
   rb-inotify
   redcarpet (~> 2.2.2)
+  redis-rails
   rspec-rails (= 2.12.2)
   sass-rails (~> 3.2.5)
   sdoc
diff --git a/app/views/events/_event.html.haml b/app/views/events/_event.html.haml
index 719f6c3787..febd72f699 100644
--- a/app/views/events/_event.html.haml
+++ b/app/views/events/_event.html.haml
@@ -1,15 +1,16 @@
 - if event.proper?
-  %div.event-item
-    %span.cgray.pull-right
-      #{time_ago_in_words(event.created_at)} ago.
+  = cache event do
+    %div.event-item
+      %span.cgray.pull-right
+        #{time_ago_in_words(event.created_at)} ago.
 
-    = image_tag gravatar_icon(event.author_email), class: "avatar s24"
+      = image_tag gravatar_icon(event.author_email), class: "avatar s24"
 
-    - if event.push?
-      = render "events/event/push", event: event
-      .clearfix
-    - elsif event.note?
-      = render "events/event/note", event: event
-    - else
-      = render "events/event/common", event: event
+      - if event.push?
+        = render "events/event/push", event: event
+        .clearfix
+      - elsif event.note?
+        = render "events/event/note", event: event
+      - else
+        = render "events/event/common", event: event
 
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 52fb8877cf..6ae0324fa8 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -40,7 +40,7 @@ Gitlab::Application.configure do
   # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
 
   # Use a different cache store in production
-  config.cache_store = :memory_store
+  config.cache_store = :redis_store
 
   # Enable serving of images, stylesheets, and JavaScripts from an asset server
   # config.action_controller.asset_host = "http://assets.example.com"
-- 
2.30.9