Commit 92dbe3b7 authored by Robert Speicher's avatar Robert Speicher

Merge branch '196371' into 'master'

Remove unneeded DB query from `emails_disabled?`

See merge request gitlab-org/gitlab!22843
parents ee4a7e56 07d2710d
...@@ -186,7 +186,11 @@ class Namespace < ApplicationRecord ...@@ -186,7 +186,11 @@ class Namespace < ApplicationRecord
# any ancestor can disable emails for all descendants # any ancestor can disable emails for all descendants
def emails_disabled? def emails_disabled?
strong_memoize(:emails_disabled) do strong_memoize(:emails_disabled) do
self_and_ancestors.where(emails_disabled: true).exists? if parent_id
self_and_ancestors.where(emails_disabled: true).exists?
else
!!emails_disabled
end
end end
end end
......
...@@ -923,6 +923,12 @@ describe Namespace do ...@@ -923,6 +923,12 @@ describe Namespace do
expect(group.emails_disabled?).to be_truthy expect(group.emails_disabled?).to be_truthy
end end
it 'does not query the db when there is no parent group' do
group = create(:group, emails_disabled: true)
expect { group.emails_disabled? }.not_to exceed_query_limit(0)
end
end end
context 'when a subgroup' do context 'when a subgroup' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment