diff --git a/app/models/user_first.rb b/app/models/user_first.rb index 6a953b5d164..4f78620379c 100644 --- a/app/models/user_first.rb +++ b/app/models/user_first.rb @@ -5,6 +5,9 @@ class UserFirst < ActiveRecord::Base end def self.create_for(user_id, type, post_id=nil) + # the usual case will be that it is already in table, don't try to insert + return false if UserFirst.exists?(user_id: user_id, first_type: types[type]) + create!(user_id: user_id, first_type: types[type], post_id: post_id) true rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique