* getting started: model setup * basic controller action & spec * somewhat working click events * pick up on impressions * there was an attempt at batching without duplicates * (better) bulk upsert service * fix specs? * touch up feed events JS * end-to-end specs?? * workers wip * fix failing user delete spec
31 lines
1.1 KiB
Ruby
31 lines
1.1 KiB
Ruby
class FeedEvent < ApplicationRecord
|
|
# These are "optional" mostly so that we can perform validated bulk inserts
|
|
# without triggering article/user validation.
|
|
# Since there are database-level constraints, it's fine to skip the automatic
|
|
# Rails-side association validation (which causes an N+1 query).
|
|
belongs_to :article, optional: true
|
|
belongs_to :user, optional: true
|
|
|
|
enum category: {
|
|
impression: 0,
|
|
click: 1,
|
|
reaction: 2,
|
|
comment: 3
|
|
}
|
|
|
|
CONTEXT_TYPE_HOME = "home".freeze
|
|
CONTEXT_TYPE_SEARCH = "search".freeze
|
|
CONTEXT_TYPE_TAG = "tag".freeze
|
|
VALID_CONTEXT_TYPES = [
|
|
CONTEXT_TYPE_HOME,
|
|
CONTEXT_TYPE_SEARCH,
|
|
CONTEXT_TYPE_TAG,
|
|
].freeze
|
|
DEFAULT_TIMEBOX = 5.minutes.freeze
|
|
|
|
validates :article_position, numericality: { only_integer: true, greater_than: 0 }
|
|
validates :context_type, inclusion: { in: VALID_CONTEXT_TYPES }, presence: true
|
|
# Since we have disabled association validation, this is handy to filter basic bad data
|
|
validates :article_id, presence: true, numericality: { only_integer: true }
|
|
validates :user_id, numericality: { only_integer: true }, allow_nil: true
|
|
end
|