diff options
author | Rémy Coutable <remy@rymai.me> | 2016-10-07 15:18:22 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-10-07 15:18:22 +0000 |
commit | 212cf8f950610570d3d2fb946ea57defd6fc04f3 (patch) | |
tree | e7faf5e3edb11b066e8df6a45f34f049283925fc /app | |
parent | 2a37e684fbcfbfc92a0fb5f1fc9cf523986e5880 (diff) | |
parent | 328ca8c47054a6d1d284bc8e16b9b0600a137916 (diff) | |
download | gitlab-ce-212cf8f950610570d3d2fb946ea57defd6fc04f3.tar.gz |
Merge branch 'rs-optimize-award_user_list-spec' into 'master'
Optimize the `award_user_list` helper spec
According to
https://gitlab.com/gitlab-org/gitlab-ce/issues/23034#note_16586657, each
test for this helper generated 1,833 queries.
Now we only generate stubbed records, and only as many as we need for
each test.
This also corrects a slight logic bug in the helper itself. When the
number of awards was greater than the limit (9 by default), _and_ the
current user was one of them, we actually included 10 names, including
"You", plus the remaining count. Now we return the correct number
regardless.
See merge request !6722
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/issues_helper.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 8b212b0327a..1644c346dd8 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -113,14 +113,13 @@ module IssuesHelper end end - def award_user_list(awards, current_user) + def award_user_list(awards, current_user, limit: 10) names = awards.map do |award| award.user == current_user ? 'You' : award.user.name end - # Take first 9 OR current user + first 9 current_user_name = names.delete('You') - names = names.first(9).insert(0, current_user_name).compact + names = names.insert(0, current_user_name).compact.first(limit) names << "#{awards.size - names.size} more." if awards.size > names.size |