diff options
author | Stan Hu <stanhu@gmail.com> | 2016-06-28 15:14:11 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-06-29 06:26:00 -0700 |
commit | 8c29b0b06554eb9549fe9bd2f33e80ce149752fd (patch) | |
tree | 9c0f24bc41ada0eba858dc21cb50ed0d300dd202 /spec/helpers | |
parent | a4b1fe4de951cb18a061b2be7b85988e6db26f5b (diff) | |
download | gitlab-ce-8c29b0b06554eb9549fe9bd2f33e80ce149752fd.tar.gz |
Memoize the maximum access level for the author of notes
In #19273, we saw that retrieving ProjectTeam#human_max_access for each
note takes the bulk of the time when rendering certain issues or merge requests.
We observe that most of the comments in an issue are typically done by the
same users. This MR memoizes the max access level by user ID.
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/notes_helper_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb new file mode 100644 index 00000000000..8325af0dcf8 --- /dev/null +++ b/spec/helpers/notes_helper_spec.rb @@ -0,0 +1,32 @@ +require "spec_helper" + +describe NotesHelper do + describe "#notes_max_access_for_users" do + let(:owner) { create(:owner) } + let(:group) { create(:group) } + let(:project) { create(:empty_project, namespace: group) } + let(:master) { create(:user) } + let(:reporter) { create(:user) } + let(:guest) { create(:user) } + + let(:owner_note) { create(:note, author: owner, project: project) } + let(:master_note) { create(:note, author: master, project: project) } + let(:reporter_note) { create(:note, author: reporter, project: project) } + let!(:notes) { [owner_note, master_note, reporter_note] } + + before do + group.add_owner(owner) + project.team << [master, :master] + project.team << [reporter, :reporter] + project.team << [guest, :guest] + end + + it 'return human access levels' do + expect(helper.note_max_access_for_user(owner_note)).to eq('Owner') + expect(helper.note_max_access_for_user(master_note)).to eq('Master') + expect(helper.note_max_access_for_user(reporter_note)).to eq('Reporter') + # Call it again to ensure value is cached + expect(helper.note_max_access_for_user(owner_note)).to eq('Owner') + end + end +end |