0

I need to check the number of items in a collection without loading the full collection (as it has over 1.5 million items and causes memory issues).

Is there an efficient way to go about this?

1
  • Going threw raw count sql may be if it's juste to get a value ?
    – Claims
    Dec 3, 2021 at 13:52

1 Answer 1

1

You can use getSize() method for this.

Usage: $collection->getSize();

getSize() method execute a count SQL query into the database and give you the count.

You can read in detail by below article.

https://webkul.com/blog/optimizing-magento-magento2-part-1/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.