add transaction to sort method to improve perfermance of SQL update

the original code is slow when sort, eg: 240 records need 9 secs to update, after change: 2 secs