diff options
author | Robert Speicher <robert@gitlab.com> | 2016-06-29 21:34:46 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-06-29 21:34:46 +0000 |
commit | eae5f8aa57d61ce17f6b4885b8da463d1d33e971 (patch) | |
tree | f86abf947b6279ab60f67b6cc570c2470b787aa9 /app/helpers | |
parent | 47648a50d7bfab644de96025a3001a666cfe7653 (diff) | |
parent | 20688cdf0711f0d7d70abdf01db5a4f3a0671c6c (diff) | |
download | gitlab-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.rb | 10 |
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 |