mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-26 00:46:12 +08:00
Adds a `browser_pageview_event_scores` side table keyed by `event_id`, holding the per-heuristic contribution as six smallint columns: - `automation_ua_score` (0 or 100) - `known_asn_score` (0 or 15) - `velocity_score` (0, 10, 20, or 35) - `churn_score` (0, 10, or 20) - `rapid_nav_score` (0 or 15) - `referrer_score` (0, 5, or 10) The side table only holds rows for events that scored above zero.
47 lines
1.5 KiB
Ruby
Vendored
47 lines
1.5 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class BrowserPageviewEvent < ActiveRecord::Base
|
|
MAX_SESSION_ID_LENGTH = 32
|
|
MAX_URL_LENGTH = 2000
|
|
MAX_REFERRER_LENGTH = 2000
|
|
MAX_USER_AGENT_LENGTH = 1000
|
|
|
|
has_one :browser_pageview_event_score, foreign_key: :event_id, dependent: :delete
|
|
|
|
before_save :truncate_fields
|
|
|
|
private
|
|
|
|
def truncate_fields
|
|
self.url = url.slice(0, MAX_URL_LENGTH) if url.present?
|
|
self.referrer = referrer.slice(0, MAX_REFERRER_LENGTH) if referrer.present?
|
|
self.user_agent = user_agent.slice(0, MAX_USER_AGENT_LENGTH) if user_agent.present?
|
|
self.session_id = session_id.slice(0, MAX_SESSION_ID_LENGTH) if session_id.present?
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: browser_pageview_events
|
|
#
|
|
# id :bigint not null, primary key
|
|
# asn :integer
|
|
# country_code :string(2)
|
|
# ip_address :inet not null
|
|
# referrer :string(2000)
|
|
# score :integer
|
|
# url :string(2000) not null
|
|
# user_agent :string(1000) not null
|
|
# created_at :datetime not null
|
|
# session_id :string(32) not null
|
|
# topic_id :integer
|
|
# user_id :integer
|
|
#
|
|
# Indexes
|
|
#
|
|
# idx_bpe_ip_ua_created_at (ip_address,user_agent,created_at)
|
|
# idx_bpe_session_created_at (session_id,created_at)
|
|
# index_browser_pageview_events_on_created_at (created_at) USING brin
|
|
# index_browser_pageview_events_on_topic_id (topic_id)
|
|
# index_browser_pageview_events_on_user_id (user_id)
|
|
#
|