diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-05-30 12:54:26 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-05-30 12:54:26 +0000 |
commit | a8901ce63dd302d008459321bd4a8007c7c8f7c7 (patch) | |
tree | 3fd3d77452416131b7d6982d4d631d414f930248 | |
parent | 1d5e5f754df345d7e3748bef4030b7210cff63c9 (diff) | |
parent | 172932eec8f234fbb665489c00f73d644fa0413e (diff) | |
download | gitlab-ce-a8901ce63dd302d008459321bd4a8007c7c8f7c7.tar.gz |
Merge branch '33032-invalid-you-directly-addressed-yourself-todo-when-using-unsubscribe' into 'master'
Resolve "Invalid 'You directly addressed yourself' TODO when using `/unsubscribe`"
Closes #33032
See merge request !11788
3 files changed, 32 insertions, 3 deletions
diff --git a/changelogs/unreleased/33032-invalid-you-directly-addressed-yourself-todo-when-using-unsubscribe.yml b/changelogs/unreleased/33032-invalid-you-directly-addressed-yourself-todo-when-using-unsubscribe.yml new file mode 100644 index 00000000000..1eaa0d0124e --- /dev/null +++ b/changelogs/unreleased/33032-invalid-you-directly-addressed-yourself-todo-when-using-unsubscribe.yml @@ -0,0 +1,5 @@ +--- +title: Fix /unsubscribe slash command creating extra todos when you were already mentioned + in an issue +merge_request: +author: diff --git a/lib/banzai/reference_parser/base_parser.rb b/lib/banzai/reference_parser/base_parser.rb index c2503fa2adc..d99a3bfa625 100644 --- a/lib/banzai/reference_parser/base_parser.rb +++ b/lib/banzai/reference_parser/base_parser.rb @@ -163,14 +163,15 @@ module Banzai # been queried the object is returned from the cache. def collection_objects_for_ids(collection, ids) if RequestStore.active? + ids = ids.map(&:to_i) cache = collection_cache[collection_cache_key(collection)] - to_query = ids.map(&:to_i) - cache.keys + to_query = ids - cache.keys unless to_query.empty? collection.where(id: to_query).each { |row| cache[row.id] = row } end - cache.values + cache.values_at(*ids) else collection.where(id: ids) end diff --git a/spec/lib/banzai/reference_parser/user_parser_spec.rb b/spec/lib/banzai/reference_parser/user_parser_spec.rb index 4ec998efe53..592ed0d2b98 100644 --- a/spec/lib/banzai/reference_parser/user_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/user_parser_spec.rb @@ -42,6 +42,29 @@ describe Banzai::ReferenceParser::UserParser, lib: true do expect(subject.referenced_by([link])).to eq([user]) end + + context 'when RequestStore is active' do + let(:other_user) { create(:user) } + + before do + RequestStore.begin! + end + + after do + RequestStore.end! + RequestStore.clear! + end + + it 'does not return users from the first call in the second' do + link['data-user'] = user.id.to_s + + expect(subject.referenced_by([link])).to eq([user]) + + link['data-user'] = other_user.id.to_s + + expect(subject.referenced_by([link])).to eq([other_user]) + end + end end context 'when the link has a data-project attribute' do @@ -74,7 +97,7 @@ describe Banzai::ReferenceParser::UserParser, lib: true do end end - describe '#nodes_visible_to_use?' do + describe '#nodes_visible_to_user' do context 'when the link has a data-group attribute' do context 'using an existing group ID' do before do |