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/models/ability.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/models/ability.rb')
-rw-r--r-- | app/models/ability.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index f33c8d61d3f..6884d99c5a6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -388,6 +388,20 @@ class Ability GroupProjectsFinder.new(group).execute(user).any? end + def can_edit_note?(user, note) + return false unless note.editable? + return false unless user.present? + return true if note.author == user + return true if user.admin? + + if note.project + max_access_level = note.project.team.max_member_access(user.id) + max_access_level >= Gitlab::Access::MASTER + else + false + end + end + def namespace_abilities(user, namespace) rules = [] |