0

i have this custom collection which is taking much time to load, so want to change into sql query how can I achieve it?

$delayedcollectioncount = Mage::getModel("customer/customer")
        ->getCollection()
        ->addAttributeToSelect('firstname, entity_id')
        ->addAttributeToFilter('grisk_college_new_id', array('in' =>$college))
        ->addFieldToFilter('group_id', array('in' => array(4,5)))
        ->addAttributeToFilter('assigned_campus_manager', array('null' => true), 'left')
        ->addAttributeToFilter('physical_verify', array('null' => true), 'left')
        ->addFieldToFilter('grisk_pv_upload_date', array('lt' => date("Y-m-d H:i:s", strtotime($configValue))))
        ->addAttributeToSort('grisk_pv_upload_date', 'DESC')
        ->count();
Murtuza Zabuawala
  • 14,814
  • 9
  • 44
  • 75
supriya mishra
  • 671
  • 1
  • 13
  • 32

1 Answers1

1

Since you only need a count and there are no limits on your query, you can just replace count with getSize.
It should be way faster.
Here are some details about the difference: Difference between getSize() and count() on collection

Marius
  • 197,939
  • 53
  • 422
  • 830
  • wow !! it worked reduce my loading time !! Thanks man!!! :) – supriya mishra Apr 24 '17 at 14:17
  • but still i want to try with query if it can reduce more . – supriya mishra Apr 24 '17 at 14:22
  • it may incorrect my counts also ? – supriya mishra Apr 24 '17 at 14:29
  • I don't think it will reduce the time much more. Because getSize actually runs one single query. and retrieve one single result. the only time you would save would be from bypassing the query builder. But honestly you don't want to do that since the customer model is and EAV model. This means it joins some tables in order to filter by attributes. Writing it as a query increases your error chances significantly. – Marius Apr 24 '17 at 14:31
  • loading time i m not able to check in test server perfectly but still, i m getting significant difference , any way just worried about correct count as a result . – supriya mishra Apr 24 '17 at 14:39