FEATURE: Create new helper method 'Discourse.stats' (#7388)

FEATURE: Create new helper method ‘Discourse.stats’ (#7388)

diff --git a/lib/discourse.rb b/lib/discourse.rb
index a6476dc..f1c9f06 100644
--- a/lib/discourse.rb
+++ b/lib/discourse.rb
@@ -468,6 +468,10 @@ module Discourse
     end
   end
 
+  def self.stats
+    @stats ||= PluginStore.new("stats")
+  end
+
   def self.current_user_provider
     @current_user_provider || Auth::DefaultCurrentUserProvider
   end
diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb
index f6b053a..8ec4ff5 100644
--- a/lib/s3_inventory.rb
+++ b/lib/s3_inventory.rb
@@ -65,7 +65,7 @@ class S3Inventory
             log "#{missing_count} of #{uploads.count} #{model.name.underscore.pluralize} are missing"
           end
 
-          $redis.set("missing_s3_#{model.table_name}", missing_count)
+          Discourse.stats.set("missing_s3_#{model.table_name}", missing_count)
         ensure
           connection.exec("DROP TABLE #{table_name}") unless connection.nil?
         end
diff --git a/spec/components/s3_inventory_spec.rb b/spec/components/s3_inventory_spec.rb
index bed0345..b673464 100644
--- a/spec/components/s3_inventory_spec.rb
+++ b/spec/components/s3_inventory_spec.rb
@@ -75,7 +75,7 @@ describe "S3Inventory" do
     end
 
     expect(output).to eq("#{upload.url}\n1 of 4 uploads are missing\n")
-    expect($redis.get("missing_s3_uploads")).to eq("1")
+    expect(Discourse.stats.get("missing_s3_uploads")).to eq(1)
   end
 
   it "should backfill etags to uploads table correctly" do

GitHub sha: a8f410a9

@eviltrout raised a valid point in FEATURE: Create new helper method 'Discourse.stats' by vinothkannans · Pull Request #7388 · discourse/discourse · GitHub. Kind of strange to be using the plugin store for a core feature.

Weird shouldn’t my comment have synched over?

Yeah it should sync both directions

I thought about this a fair bit, it is definitely not mega hygienic, but I worry about crating a whole new table here just to store 1 row/column. A new generic system for 1 value is also a worry

O actually @eviltrout comment’s didn’t sync because the comment was in the PR.

We do need a follow up I think, pretty sure this is not multisite friendly

2 Likes

FIX: make 'stats' method compatible with multisite.

I’m unable to find a better solution here.