REFACTOR: Move the multisite middleware to the front

Both request tracking and message bus rely on multisite before the
middleware has run which is not ideal.
This commit is contained in:
Daniel Waterworth
2020-03-30 12:01:06 +01:00
parent 8a50ab45aa
commit a91843f0dc
3 changed files with 21 additions and 24 deletions

View File

@ -51,14 +51,6 @@ class Middleware::RequestTracker
@app = app
end
def self.log_request_on_site(data, host)
RailsMultisite::ConnectionManagement.with_hostname(host) do
unless Discourse.pg_readonly_mode?
log_request(data)
end
end
end
def self.log_request(data)
status = data[:status]
track_view = data[:track_view]
@ -135,7 +127,6 @@ class Middleware::RequestTracker
# we got to skip this on error ... its just logging
data = self.class.get_data(env, result, info) rescue nil
host = RailsMultisite::ConnectionManagement.host(env)
if data
if result && (headers = result[1])
@ -146,7 +137,7 @@ class Middleware::RequestTracker
@@detailed_request_loggers.each { |logger| logger.call(env, data) }
end
log_later(data, host)
log_later(data)
end
end
@ -296,10 +287,11 @@ class Middleware::RequestTracker
end
end
def log_later(data, host)
Scheduler::Defer.later("Track view", _db = nil) do
self.class.log_request_on_site(data, host)
def log_later(data)
Scheduler::Defer.later("Track view") do
unless Discourse.pg_readonly_mode?
self.class.log_request(data)
end
end
end
end