mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: rudimentary view tracking wired in
This commit is contained in:
parent
e105f0965c
commit
c150c55e2d
3 changed files with 65 additions and 8 deletions
|
@ -60,8 +60,12 @@ module Middleware
|
|||
@env["REQUEST_METHOD"] == "GET"
|
||||
end
|
||||
|
||||
def has_auth_cookie?
|
||||
CurrentUser.has_auth_cookie?(@env)
|
||||
end
|
||||
|
||||
def cacheable?
|
||||
!!(!CurrentUser.has_auth_cookie?(@env) && get?)
|
||||
!!(!has_auth_cookie? && get?)
|
||||
end
|
||||
|
||||
def cached
|
||||
|
@ -110,9 +114,36 @@ module Middleware
|
|||
@app = app
|
||||
end
|
||||
|
||||
def self.log_request_on_site(env, helper=nil)
|
||||
host = RailsMultisite::ConnectionManagement.host(env)
|
||||
RailsMultisite::ConnectionManagement.with_hostname(host) do
|
||||
log_request(env,helper)
|
||||
end
|
||||
end
|
||||
|
||||
def self.log_request(env,helper=nil)
|
||||
|
||||
helper ||= Helper.new(env)
|
||||
|
||||
type =
|
||||
if helper.is_crawler?
|
||||
:crawler
|
||||
elsif helper.has_auth_cookie?
|
||||
:logged_in
|
||||
else
|
||||
:anon
|
||||
end
|
||||
|
||||
ApplicationRequest.increment!(type)
|
||||
end
|
||||
|
||||
def call(env)
|
||||
helper = Helper.new(env)
|
||||
|
||||
Scheduler::Defer.later "Track view" do
|
||||
self.class.log_request_on_site(env,helper)
|
||||
end
|
||||
|
||||
if helper.cacheable?
|
||||
helper.cached or helper.cache(@app.call(env))
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue