Optimize counter

decrease sql selects/updates/inserts