Pushed updateCategoryCounts() to transaction end to reduce contention.

* This can really be a problem if locks are held during file related operations.

Change-Id: I00107ffc9951915d3af6002b258b3dae2de5fa92
(cherry picked from commit c3e39d2b6d5f6895389bd9acb38c4dfa6b243890)