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

This was not causing any known issue, because the system user ID is always the same across all sites. However, we should cache this on a per-site basis to be safe.
This commit is contained in:
David Taylor 2019-10-31 15:16:26 +00:00 committed by GitHub
parent 15b25547bb
commit 1f88ecf6d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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