diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-11-15 15:47:10 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-11-16 14:59:38 +0100 |
commit | 3e561736b2eb4866b75c57c01769586f058a2f8d (patch) | |
tree | 6e136d37d558b14bfbc2505f8b8f564fa96eab6f /spec/models/key_spec.rb | |
parent | 81e94ce1761b48b73be2a8d71938dfe934921e35 (diff) | |
download | gitlab-ce-3e561736b2eb4866b75c57c01769586f058a2f8d.tar.gz |
Cache the number of user SSH keyscache-user-keys-count
By caching the number of personal SSH keys we reduce the number of
queries necessary on pages such as ProjectsController#show (which can
end up querying this data multiple times).
The cache is refreshed/flushed whenever an SSH key is added, removed, or
when a user is removed.
Diffstat (limited to 'spec/models/key_spec.rb')
-rw-r--r-- | spec/models/key_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 81c2057e175..4cd9e3f4f1d 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -166,4 +166,27 @@ describe Key, :mailer do expect(key.public_key.key_text).to eq(valid_key) end end + + describe '#refresh_user_cache', :use_clean_rails_memory_store_caching do + context 'when the key belongs to a user' do + it 'refreshes the keys count cache for the user' do + expect_any_instance_of(Users::KeysCountService) + .to receive(:refresh_cache) + .and_call_original + + key = create(:personal_key) + + expect(Users::KeysCountService.new(key.user).count).to eq(1) + end + end + + context 'when the key does not belong to a user' do + it 'does nothing' do + expect_any_instance_of(Users::KeysCountService) + .not_to receive(:refresh_cache) + + create(:key) + end + end + end end |