VE-1497: Performance optimization - cache locally count result