mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #3593 from tgxworld/cache_results_on_about_page
Cache results on about page
This commit is contained in:
10
spec/jobs/about_stats_spec.rb
Normal file
10
spec/jobs/about_stats_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Jobs::AboutStats do
|
||||
it 'caches the stats' do
|
||||
stats = { "visited" => 10 }
|
||||
About.any_instance.expects(:stats).returns(stats)
|
||||
$redis.expects(:setex).with(About.stats_cache_key, 35.minutes, stats.to_json)
|
||||
expect(described_class.new.execute({})).to eq(stats)
|
||||
end
|
||||
end
|
||||
10
spec/jobs/dashboard_stats_spec.rb
Normal file
10
spec/jobs/dashboard_stats_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Jobs::DashboardStats do
|
||||
it 'caches the stats' do
|
||||
json = { "visited" => 10 }
|
||||
AdminDashboardData.any_instance.expects(:as_json).returns(json)
|
||||
$redis.expects(:setex).with(AdminDashboardData.stats_cache_key, 35.minutes, json.to_json)
|
||||
expect(described_class.new.execute({})).to eq(json)
|
||||
end
|
||||
end
|
||||
9
spec/models/about_spec.rb
Normal file
9
spec/models/about_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe About do
|
||||
|
||||
describe 'stats cache' do
|
||||
include_examples 'stats cachable'
|
||||
end
|
||||
|
||||
end
|
||||
@@ -244,4 +244,8 @@ describe AdminDashboardData do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'stats cache' do
|
||||
include_examples 'stats cachable'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
23
spec/support/shared_examples_for_stats_cacheable.rb
Normal file
23
spec/support/shared_examples_for_stats_cacheable.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
shared_examples_for 'stats cachable' do
|
||||
describe 'fetch_cached_stats' do
|
||||
it 'returns the cached stats' do
|
||||
begin
|
||||
stats = { "visits" => 10 }
|
||||
$redis.set(described_class.stats_cache_key, stats.to_json)
|
||||
expect(described_class.fetch_cached_stats).to eq(stats)
|
||||
ensure
|
||||
$redis.del(described_class.stats_cache_key)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns nil if no stats has been cached' do
|
||||
expect(described_class.fetch_cached_stats).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'fetch_stats' do
|
||||
it 'has been implemented' do
|
||||
expect{ described_class.fetch_stats }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user