Using databaseManager.getFoundSetDataProviderAsArray() will give you an array of your 5000 records of a specific column. So this is a very expensive action.
databaseManager.getFoundSetCount(foundset) is the preferred way to get a total count of your foundset.
And databaseManager.getFoundSetCount() lets the database sort out how many records there are, so it’s the fastest way possible. If it’s not performing, you should have a look at the Performance log on the admin pages to see the query being fired and then see if the database can be optimized (by adding indexes) to give you the result faster.
Thanks for the input. After trying many different methods, you are both correct in the fact that databaseManager.getFoundSetCount() is the fastest possible method in which to get a foundsets count. I was just hoping there was something that cmight be less expensive. We utilize this call in numerous places in our code, and depending on the size of the foundset, it can slow our system down quite significantly.
let me get this straight! getFoundSetCount will take 1 minute with only 5000 records??
which database are you using? there must be something wrong. We use it also a lot, with MANY MANY more records…
databaseManager.getFoundSetCount() does no more then taking the query from the foundset (select pk from table where …) and converts it to a select count (select count(1) from table where …).
In case of joins (for example when you have a related search condition), a distinct(pk) is added.
What shows on top in the admin page->performance data when you run the foundsetcount?