docbrown/app/models/page_view.rb
Ben Halpern e1b1fe3ed7
Declare winner in feed_top_articles_query test (#12308)
* Declare winner in feed_top_articles_query test

* Some WIP modifications to lfe

* Fix up tests and generalize

* Fix style

* Adjust tests to handle different field test scenarios

* Remove socre_randomness tests

* Fix test to fit stub

* Update app/workers/users/record_field_test_event_worker.rb
2021-02-04 13:02:00 -05:00

38 lines
789 B
Ruby

class PageView < ApplicationRecord
belongs_to :user, optional: true
belongs_to :article
before_create :extract_domain_and_path
after_create_commit :record_field_test_event
private
def extract_domain_and_path
return unless referrer
parsed_url = Addressable::URI.parse(referrer)
self.domain = parsed_url.domain
self.path = parsed_url.path
end
def article_searchable_tags
article.cached_tag_list
end
def article_searchable_text
article.body_text[0..350]
end
def article_tags
article.decorate.cached_tag_list_array
end
def record_field_test_event
return if FieldTest.config["experiments"].nil?
return unless user_id
Users::RecordFieldTestEventWorker
.perform_async(user_id, "user_creates_pageview")
end
end