mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 21:10:17 +08:00
avoid exception for general case
This commit is contained in:
parent
bc97e09dde
commit
4f10b5e940
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user