A platform for community discussion. Free, open, simple.
DEV: Report category counts per type in stats (#44329)
Régis Hanol8bd7baf033de
diff --git a/app/models/stat.rb b/app/models/stat.rbindex bf2eec1b202..aefee027230 100644--- a/app/models/stat.rb+++ b/app/models/stat.rb@@ -67,6 +67,9 @@ class StatStat.new("steps", stat_type: :onboarding) { Statistics.onboarding_steps },Stat.new("panel", stat_type: :onboarding) { Statistics.onboarding_panel },Stat.new("minutes_to", stat_type: :onboarding) { Statistics.onboarding_minutes_to },+ Stat.new("categories", stat_type: :category_types) do+ Categories::TypeRegistry.configured_counts+ end,]if SiteSetting.display_eu_visitor_statsdiff --git a/app/services/categories/type_registry.rb b/app/services/categories/type_registry.rbindex 2b3f0cec59f..e054b6b380c 100644--- a/app/services/categories/type_registry.rb+++ b/app/services/categories/type_registry.rb@@ -87,6 +87,12 @@ module Categoriesendend+ # Every category is a discussion category unless configured otherwise,+ # so that type never has a count of its own.+ def configured_counts+ counts.except(Categories::Types::Discussion.type_id)+ end+def non_discussion_category_idstypes.valuesdiff --git a/spec/lib/plugin/instance_spec.rb b/spec/lib/plugin/instance_spec.rbindex a69c2009ca5..ac19b00eedc 100644--- a/spec/lib/plugin/instance_spec.rb+++ b/spec/lib/plugin/instance_spec.rb@@ -133,9 +133,9 @@ TEXT:participating_users_last_day,:participating_users_7_days,:participating_users_30_days,- # onboarding stats are grouped under their stat type rather than being- # flat top-level keys+ # grouped under their stat type rather than being flat top-level keys:onboarding,+ :category_types,)enddiff --git a/spec/models/stat_spec.rb b/spec/models/stat_spec.rbindex d9d25cee6c0..ca6353b19f1 100644--- a/spec/models/stat_spec.rb+++ b/spec/models/stat_spec.rb@@ -15,8 +15,14 @@ RSpec.describe Stat do)end- it "keeps the onboarding stats out of the public API stats" do- expect(Stat.api_stats.keys).not_to include(:onboarding)+ it "counts the categories of each configured type" do+ Categories::TypeRegistry.stubs(:configured_counts).returns({ support: 2, ideas: 1 })++ expect(Stat.all_stats[:category_types]).to eq(categories_support: 2, categories_ideas: 1)+ end++ it "keeps the site setup stats out of the public API stats" do+ expect(Stat.api_stats.keys).not_to include(:onboarding, :category_types)endcontext "when display_eu_visitor_stats is enabled" dodiff --git a/spec/services/categories/type_registry_spec.rb b/spec/services/categories/type_registry_spec.rbindex 56f97f4dfab..6f8a6888727 100644--- a/spec/services/categories/type_registry_spec.rb+++ b/spec/services/categories/type_registry_spec.rb@@ -181,6 +181,12 @@ RSpec.describe Categories::TypeRegistry doendend+ describe ".configured_counts" do+ it "leaves out the implicit discussion type" do+ expect(described_class.configured_counts).to eq(described_class.counts.except(:discussion))+ end+ end+describe ".register" dolet(:test_type) doClass.new(Categories::Types::Base).tap { |t| t.type_id(:test_registry_type) }