diff options
author | Mario de la Ossa <mariodelaossa@gmail.com> | 2019-07-03 17:12:02 -0600 |
---|---|---|
committer | Mario de la Ossa <mariodelaossa@gmail.com> | 2019-07-10 21:35:43 -0600 |
commit | e5705f5c540755a672de5acf9d5710c24ccc6b27 (patch) | |
tree | ba5609a78b4b926c4a96f29668af76bd2bc12cf9 /spec/lib/banzai | |
parent | 62e52ac6a8130c080f498ee2f76ef50b8c209f0f (diff) | |
download | gitlab-ce-e5705f5c540755a672de5acf9d5710c24ccc6b27.tar.gz |
Banzai - avoid redis if attr is in DB cachebanzai-avoid-redis-if-db-cache
When cache_collection_render runs we end up reading and writing
things to redis even if we already have the rendered field cached
in the DB. This commit avoids using redis at all whenever we have
the field already rendered in the DB cache.
Diffstat (limited to 'spec/lib/banzai')
-rw-r--r-- | spec/lib/banzai/renderer_spec.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/lib/banzai/renderer_spec.rb b/spec/lib/banzai/renderer_spec.rb index aa828e2f0e9..a099f7482c1 100644 --- a/spec/lib/banzai/renderer_spec.rb +++ b/spec/lib/banzai/renderer_spec.rb @@ -19,6 +19,24 @@ describe Banzai::Renderer do object end + describe '#cache_collection_render' do + let(:merge_request) { fake_object(fresh: true) } + let(:context) { { cache_key: [merge_request, 'field'], rendered: merge_request.field_html } } + + context 'when an item has a rendered field' do + before do + allow(merge_request).to receive(:field).and_return('This is the field') + allow(merge_request).to receive(:field_html).and_return('This is the field') + end + + it 'does not touch redis if the field is in the cache' do + expect(Rails).not_to receive(:cache) + + described_class.cache_collection_render([{ text: merge_request.field, context: context }]) + end + end + end + describe '#render_field' do let(:renderer) { described_class } |