mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
refactor traffic report
split traffic report in 2, page view vs raw traffic hide raw traffic report by default improve flushing logic for application reqs
This commit is contained in:
@ -1,9 +1,21 @@
|
||||
class ApplicationRequest < ActiveRecord::Base
|
||||
enum req_type: %i(total success background topic_anon topic_logged_in topic_crawler server_error client_error redirect)
|
||||
enum req_type: %i(http_total
|
||||
http_2xx
|
||||
http_background
|
||||
http_3xx
|
||||
http_4xx
|
||||
http_5xx
|
||||
page_view_crawler
|
||||
page_view_logged_in
|
||||
page_view_anon)
|
||||
|
||||
cattr_accessor :autoflush
|
||||
cattr_accessor :autoflush, :autoflush_seconds, :last_flush
|
||||
# auto flush if backlog is larger than this
|
||||
self.autoflush = 200
|
||||
self.autoflush = 2000
|
||||
|
||||
# auto flush if older than this
|
||||
self.autoflush_seconds = 5.minutes
|
||||
self.last_flush = Time.now
|
||||
|
||||
def self.increment!(type, opts=nil)
|
||||
key = redis_key(type)
|
||||
@ -13,6 +25,11 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
autoflush = (opts && opts[:autoflush]) || self.autoflush
|
||||
if autoflush > 0 && val >= autoflush
|
||||
write_cache!
|
||||
return
|
||||
end
|
||||
|
||||
if (Time.now - last_flush).to_i > autoflush_seconds
|
||||
write_cache!
|
||||
end
|
||||
end
|
||||
|
||||
@ -23,6 +40,8 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
return
|
||||
end
|
||||
|
||||
self.last_flush = Time.now
|
||||
|
||||
date = date.to_date
|
||||
|
||||
# this may seem a bit fancy but in so it allows
|
||||
|
Reference in New Issue
Block a user