diff options
author | Stan Hu <stanhu@gmail.com> | 2016-07-19 21:52:31 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-07-26 15:33:05 -0700 |
commit | d1ea2bca61dff21948024d897e1d4475123a10e8 (patch) | |
tree | db9a7093c70ece66eb66b09bf7d6288246ae25cd /app/helpers/notes_helper.rb | |
parent | 95efb6f1163b7c2c40d03ddd834016905fc45b50 (diff) | |
download | gitlab-ce-d1ea2bca61dff21948024d897e1d4475123a10e8.tar.gz |
Optimize maximum user access level lookup in loading of notes
NotesHelper#note_editable? and ProjectTeam#human_max_access currently
take about 16% of the load time of an issue page. This MR preloads
the maximum access level of users for all notes in issues and merge
requests with several queries instead of one per user and caches
the result in RequestStore.
Diffstat (limited to 'app/helpers/notes_helper.rb')
-rw-r--r-- | app/helpers/notes_helper.rb | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 0f60dd828ab..0c47abe0fba 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -7,7 +7,7 @@ module NotesHelper end def note_editable?(note) - note.editable? && can?(current_user, :admin_note, note) + Ability.can_edit_note?(current_user, note) end def noteable_json(noteable) @@ -87,14 +87,13 @@ module NotesHelper end 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 + def preload_max_access_for_authors(notes, project) + user_ids = notes.map(&:author_id) + project.team.max_member_access_for_user_ids(user_ids) + end - full_key = { project: note.project, user_id: note.author_id } - @max_access_by_user_id[full_key] + def note_max_access_for_user(note) + note.project.team.human_max_access(note.author_id) end def discussion_diff_path(discussion) |