discourse/app/models/incoming_referer.rb
Sam cb0ecd9ff1 PERF: store topic views in a topic view table
* cut down on storage of the work Topic, 3 times per row (in 2 indexes)
* only store one view per user per topic
* only store one view per ip per topic
2014-08-04 19:07:55 +10:00

34 lines
823 B
Ruby

class IncomingReferer < ActiveRecord::Base
belongs_to :incoming_domain
def self.add!(opts)
domain_id = opts[:incoming_domain_id]
domain_id ||= opts[:incoming_domain].id
path = opts[:path]
current = find_by(path: path, incoming_domain_id: domain_id)
return current if current
begin
current = create!(path: path, incoming_domain_id: domain_id)
rescue
# duplicates
end
current || find_by(path: path, incoming_domain_id: domain_id)
end
end
# == Schema Information
#
# Table name: incoming_referers
#
# id :integer not null, primary key
# path :string(1000) not null
# incoming_domain_id :integer not null
#
# Indexes
#
# index_incoming_referers_on_path_and_incoming_domain_id (path,incoming_domain_id) UNIQUE
#