Retrieving all the records from the database and counting them in PHP is very wasteful nonsense. It is for these databases.
A find('count')just makes a SQL query like SELECT COUNT(*) FROM … WHERE …, which is actually the fastest way. Add the appropriate conditions to get the right score, you may need to refresh your SQL to find out what conditions they are.
There is also a special counter-caching that you might want to examine if you consider hasMany a relationship.
source
share