[BUGFIX] Calculate count of records instead of using a query