Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensure About#stats uses the cache (#28634)

Joffrey JAFFEUX4f705b3146b7
diff --git a/app/models/about.rb b/app/models/about.rb
index 26c17495d64..d385e19c680 100644
--- a/app/models/about.rb
+++ b/app/models/about.rb
@@ -81,7 +81,7 @@ class About
end
def stats
- @stats ||= About.fetch_stats
+ @stats ||= About.fetch_cached_stats
end
def category_moderators
diff --git a/spec/models/about_spec.rb b/spec/models/about_spec.rb
index 713ab2f22b9..bf70caeef71 100644
--- a/spec/models/about_spec.rb
+++ b/spec/models/about_spec.rb
@@ -15,6 +15,8 @@ RSpec.describe About do
after { DiscoursePluginRegistry.reset! }
describe "#stats" do
+ use_redis_snapshotting
+
it "adds plugin stats to the output" do
stats = { :last_day => 1, "7_days" => 10, "30_days" => 100, :count => 1000 }
register_stat("some_group", Proc.new { stats })
@@ -28,6 +30,13 @@ RSpec.describe About do
)
end
+ it "uses the cache" do
+ cold_cache_count = track_sql_queries { described_class.new.stats }.count
+ hot_cache_count = track_sql_queries { described_class.new.stats }.count
+
+ expect(cold_cache_count + hot_cache_count).to eq(cold_cache_count)
+ end
+
it "does not add plugin stats to the output if they are missing one of the required keys" do
stats = { "7_days" => 10, "30_days" => 100, :count => 1000 }
register_stat("some_group", Proc.new { stats })