summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormicael.bergeron <micaelbergeron@gmail.com>2017-12-06 10:57:10 -0500
committermicael.bergeron <micaelbergeron@gmail.com>2017-12-07 09:02:55 -0500
commit17075a0bdc0c271e9f7a4f25829c0517656d5871 (patch)
tree6b49ff0f910fd95063d9526e35c5b26c51628f3b
parent16c8b91092fa0fe0b5822648c22ee545e11cb4bc (diff)
downloadgitlab-ce-17075a0bdc0c271e9f7a4f25829c0517656d5871.tar.gz
cache the Note#commit method
-rw-r--r--app/models/note.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index fb4a52f8c6e..c4c2ab8e67d 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -231,19 +231,17 @@ class Note < ActiveRecord::Base
end
def commit
- project.commit(commit_id) if commit_id.present?
+ @commit ||= project.commit(commit_id) if commit_id.present?
end
# override to return commits, which are not active record
def noteable
- if for_commit?
- @commit ||= commit
- else
- super
- end
- # Temp fix to prevent app crash
- # if note commit id doesn't exist
+ return commit if for_commit?
+
+ super
rescue
+ # Temp fix to prevent app crash
+ # if note commit id doesn't exist
nil
end