Skip to content

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

FIX: Cache `Discourse.system_user` separately for each multisite tenant (#8276)

David Taylor1f88ecf6d853
diff --git a/lib/discourse.rb b/lib/discourse.rb
index b7b65762fb1..561a4e979fa 100644
--- a/lib/discourse.rb
+++ b/lib/discourse.rb
@@ -536,7 +536,9 @@ module Discourse
SYSTEM_USER_ID ||= -1
def self.system_user
- @system_user ||= User.find_by(id: SYSTEM_USER_ID)
+ @system_users ||= {}
+ current_db = RailsMultisite::ConnectionManagement.current_db
+ @system_users[current_db] ||= User.find_by(id: SYSTEM_USER_ID)
end
def self.store
diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb
index 76a832c6d08..70559a5038d 100644
--- a/spec/components/discourse_spec.rb
+++ b/spec/components/discourse_spec.rb
@@ -130,6 +130,12 @@ describe Discourse do
end
+ context '#system_user' do
+ it 'returns the system user' do
+ expect(Discourse.system_user.id).to eq(-1)
+ end
+ end
+
context "#store" do
it "returns LocalStore by default" do