diff options
author | Stan Hu <stanhu@gmail.com> | 2016-06-28 15:14:11 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-06-29 06:26:00 -0700 |
commit | 8c29b0b06554eb9549fe9bd2f33e80ce149752fd (patch) | |
tree | 9c0f24bc41ada0eba858dc21cb50ed0d300dd202 /app/helpers/notes_helper.rb | |
parent | a4b1fe4de951cb18a061b2be7b85988e6db26f5b (diff) | |
download | gitlab-ce-8c29b0b06554eb9549fe9bd2f33e80ce149752fd.tar.gz |
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.rb | 8 |
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 |