diff options
author | Robert Speicher <robert@gitlab.com> | 2016-07-29 19:54:37 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-07-29 19:54:37 +0300 |
commit | dac2e0c43d8ca3e4c593a230dcef4eb9918a4263 (patch) | |
tree | 7e3b8967989b992d581df9a7e689f74839056997 /lib/banzai | |
parent | 34c083a184b98372b3b28a661d5cf41e0f2d8259 (diff) | |
parent | 002ad215818450d2cbbc5fa065850a953dc7ada8 (diff) |
Merge branch 'ability-batch-issue-checking' into 'master'
Optimize checking if a user can read multiple issues
## What does this MR do?
This optimizes various parts of the code so it can more efficiently check if a user can read a list of issues.
## Are there points in the code the reviewer needs to double check?
Yes, in particular `Ability.issues_readable_by_user` should be checked to make sure it correctly allows/restricts access to issues.
## Why was this MR needed?
Currently the general approach to checking if one can read an issue is to iterate over the issues to check and call `can?(user, :read_issue, issue)` for every issue. This is not efficient as the same work has to be done for every issue.
## What are the relevant issue numbers?
* #15607
* #17463
See merge request !5370
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/reference_parser/issue_parser.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/banzai/reference_parser/issue_parser.rb b/lib/banzai/reference_parser/issue_parser.rb index f306079d833..6c20dec5734 100644 --- a/lib/banzai/reference_parser/issue_parser.rb +++ b/lib/banzai/reference_parser/issue_parser.rb @@ -9,10 +9,11 @@ module Banzai issues = issues_for_nodes(nodes) - nodes.select do |node| - issue = issue_for_node(issues, node) + readable_issues = Ability. + issues_readable_by_user(issues.values, user).to_set - issue ? can?(user, :read_issue, issue) : false + nodes.select do |node| + readable_issues.include?(issue_for_node(issues, node)) end end |