N+1 queries in notes/_actions.html partial due to can? checks

In app/views/projects/notes/_actions.html, we have multiple can? checks that do repeated permission checks that show up in the profile:

  • can?(current_user, :resolve_note, note)
  • can?(current_user, :award_emoji, note)

You can see this in http://profiler.gitlap.com/20180322/e13f63e1-f91b-41c1-9234-244189201a7c.html.gz.

This is adding to about 6% of the load time of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9546:

image

image

What's ironic is that even for an anonymous user, these permission checks are being run even though the user probably has note_max_access_for_user as 0.

gitlab-ce@04c7d0d55500e6f118bd17153f3af11e83fce826 was recently added.

/cc: @reprazent, @smcgivern

Assignee Loading
Time tracking Loading