summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-10-02 18:57:13 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-10-02 19:00:41 -0400
commit5e3be9cda0e23e2c62a3e3b08791357ce572d998 (patch)
tree3366e026075f8f783087b0668fb59cd2a5c36bd0 /app
parent38ca52f33b6a6824268f3dc92cf5ca13ad737c20 (diff)
downloadgitlab-ce-5e3be9cda0e23e2c62a3e3b08791357ce572d998.tar.gz
Cache the value of safe_message
Also, just for extra paranoia, only call safe_message once in the decorator methods Adds specs to make sure it still works
Diffstat (limited to 'app')
-rw-r--r--app/decorators/commit_decorator.rb22
-rw-r--r--app/models/commit.rb2
2 files changed, 14 insertions, 10 deletions
diff --git a/app/decorators/commit_decorator.rb b/app/decorators/commit_decorator.rb
index c85f740027e..777580a6d5e 100644
--- a/app/decorators/commit_decorator.rb
+++ b/app/decorators/commit_decorator.rb
@@ -16,13 +16,15 @@ class CommitDecorator < ApplicationDecorator
# In case this first line is longer than 80 characters, it is cut off
# after 70 characters and ellipses (`&hellp;`) are appended.
def title
- return no_commit_message if safe_message.blank?
+ title = safe_message
- title_end = safe_message.index(/\n/)
- if (!title_end && safe_message.length > 80) || (title_end && title_end > 80)
- safe_message[0..69] << "&hellip;".html_safe
+ return no_commit_message if title.blank?
+
+ title_end = title.index(/\n/)
+ if (!title_end && title.length > 80) || (title_end && title_end > 80)
+ title[0..69] << "&hellip;".html_safe
else
- safe_message.split(/\n/, 2).first
+ title.split(/\n/, 2).first
end
end
@@ -30,11 +32,13 @@ class CommitDecorator < ApplicationDecorator
#
# cut off, ellipses (`&hellp;`) are prepended to the commit message.
def description
- title_end = safe_message.index(/\n/)
- if (!title_end && safe_message.length > 80) || (title_end && title_end > 80)
- "&hellip;".html_safe << safe_message[70..-1]
+ description = safe_message
+
+ title_end = description.index(/\n/)
+ if (!title_end && description.length > 80) || (title_end && title_end > 80)
+ "&hellip;".html_safe << description[70..-1]
else
- safe_message.split(/\n/, 2)[1].try(:chomp)
+ description.split(/\n/, 2)[1].try(:chomp)
end
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index aba21762126..a070e830680 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -107,7 +107,7 @@ class Commit
end
def safe_message
- utf8 message
+ @safe_message ||= utf8 message
end
def created_at