Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-06-29 01:14:11 +0300
committerStan Hu <stanhu@gmail.com>2016-06-29 16:26:00 +0300
commit8c29b0b06554eb9549fe9bd2f33e80ce149752fd (patch)
tree9c0f24bc41ada0eba858dc21cb50ed0d300dd202 /app/helpers/notes_helper.rb
parenta4b1fe4de951cb18a061b2be7b85988e6db26f5b (diff)
Memoize the maximum access level for the author of notes
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.
Diffstat (limited to 'app/helpers/notes_helper.rb')
-rw-r--r--app/helpers/notes_helper.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb
index b401c8385be..80d588aaf5e 100644
--- a/app/helpers/notes_helper.rb
+++ b/app/helpers/notes_helper.rb
@@ -69,4 +69,12 @@ 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)
+ user_id = note.author.id
+ project = note.project
+ @max_access_by_user_id ||= Hash.new { |hash, key| hash[key] = project.team.human_max_access(key) }
+
+ @max_access_by_user_id[user_id]
+ end
end