Actually, that's not quite right. You'll need to get the warning_id from the content entity--assuming it has one--and ensure that it's zero if it's an insert. Calling getContent should ensure that a read lock is taken out on the entity within the transaction.
This could also be resolved by adding a unique constraint on xf_warning for (content_type, content_id)
. content_type and content_id would need to be made nullable, and warnings associated with users--a bit of a redundant concept--would need to have (null, null)
for those columns instead of ('user', user_id)
. That would be a breaking change, though.