mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 04:43:37 +08:00
FIX: ensure About#stats uses the cache (#28634)
Prior to this fix we were calling `fetch_stats` which is never checking if we have a cache entry. This call is making a lot of SQL calls, so it's better to use the cache.
This commit is contained in:
parent
8b6c5da755
commit
4f705b3146
|
@ -81,7 +81,7 @@ class About
|
|||
end
|
||||
|
||||
def stats
|
||||
@stats ||= About.fetch_stats
|
||||
@stats ||= About.fetch_cached_stats
|
||||
end
|
||||
|
||||
def category_moderators
|
||||
|
|
|
@ -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 })
|
||||
|
|
Loading…
Reference in New Issue
Block a user