Log write after the db query, not before