From 3 queries to 1 with Rails upsert

How I replaced a find_or_create_by + lock + update_columns pattern with a single upsert call.