summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-06-29 21:34:46 +0000
committerRobert Speicher <robert@gitlab.com>2016-06-29 21:34:46 +0000
commiteae5f8aa57d61ce17f6b4885b8da463d1d33e971 (patch)
treef86abf947b6279ab60f67b6cc570c2470b787aa9 /app/helpers
parent47648a50d7bfab644de96025a3001a666cfe7653 (diff)
parent20688cdf0711f0d7d70abdf01db5a4f3a0671c6c (diff)
downloadgitlab-ce-eae5f8aa57d61ce17f6b4885b8da463d1d33e971.tar.gz
Merge branch 'cache-max-user-access-name' into 'master'
Memoize the maximum access level for the author of notes Cache the maximum access level for each user in a map in the controller In #19273, we saw that retrieving ProjectTeam#human_max_access for each note takes the bulk of the time when rendering certain issues or merge requests. We observe that most of the comments in an issue are typically done by the same users. This MR memoizes the max access level by user ID. See merge request !4982
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/notes_helper.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb
index b401c8385be..e85ba76887d 100644
--- a/app/helpers/notes_helper.rb
+++ b/app/helpers/notes_helper.rb
@@ -69,4 +69,14 @@ module NotesHelper
button_tag 'Reply...', class: 'btn btn-text-field js-discussion-reply-button',
data: data, title: 'Add a reply'
end
+
+ def note_max_access_for_user(note)
+ @max_access_by_user_id ||= Hash.new do |hash, key|
+ project = key[:project]
+ hash[key] = project.team.human_max_access(key[:user_id])
+ end
+
+ full_key = { project: note.project, user_id: note.author_id }
+ @max_access_by_user_id[full_key]
+ end
end