0009712: memory limit reached on search phones
authorAlexander Stintzing <a.stintzing@metaways.de>
Thu, 27 Feb 2014 10:12:39 +0000 (11:12 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 6 Mar 2014 20:26:08 +0000 (21:26 +0100)
when searching phones in the phone app,
we run in memory limitation error

https://forge.tine20.org/mantisbt/view.php?id=9712

Change-Id: Ia4aea73f766397e8cfbc97febf3496afedc7e36a
Reviewed-on: http://gerrit.tine20.com/customers/374
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Phone/JsonTest.php
tine20/Phone/Model/CallFilter.php

index 94375ad..df0ba86 100644 (file)
@@ -298,7 +298,8 @@ class Phone_JsonTest extends TestCase
         );
 
         $this->_objects['filter2'] = array(
-            array('field' => 'query', 'operator' => 'contains', 'value' => '05036')
+            array('field' => 'query', 'operator' => 'contains', 'value' => '05036'),
+            array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone1']->getId())))
         );
         
         $this->_objects['filter2a'] = array(
@@ -352,20 +353,17 @@ class Phone_JsonTest extends TestCase
      */
     public function testGetCalls()
     {
-        // search calls without phone_id filter -> the calls of all phones of the user are returned
+        // search calls without phone_id filter -> at least one call will be returned
         $result = $this->_json->searchCalls($this->_objects['filter1'], $this->_objects['paging']);
-        $this->assertEquals(3, $result['totalcount']);
+        $this->assertGreaterThanOrEqual(1, $result['totalcount']);
+        $this->assertLessThanOrEqual(2, $result['totalcount']);
         
-        // search query -> '05036' -> the user has made 2 calls, another made one call, 2 is correct than
+        // search query -> '05036' -> the user has made 2 calls each with another phone, another made one call, 1 is correct then
         $result = $this->_json->searchCalls($this->_objects['filter2'], $this->_objects['paging']);
-        $this->assertEquals(2, $result['totalcount'], 'query filter not working');
-        $result = $this->_json->searchCalls($this->_objects['filter2b'], $this->_objects['paging']);
-        $this->assertEquals(2, $result['totalcount'], 'destination filter not working');
+        $this->assertEquals(1, $result['totalcount'], 'query filter not working');
         
-        $call2 = $result['results'][0];
-        
-        $this->assertEquals($this->_objects['call2']->destination, $call2['destination'], 'destination mismatch: ' . print_r($this->_objects['call2']->toArray(), true));
-        $this->assertEquals($this->_objects['call2']->getId(), $call2['id']);
+        $result = $this->_json->searchCalls($this->_objects['filter2b'], $this->_objects['paging']);
+        $this->assertEquals(1, $result['totalcount'], 'destination filter not working');
         
         // search for phone_id
         $result = $this->_json->searchCalls($this->_objects['filter3'], $this->_objects['paging']);
index cd2bff8..7c4c879 100644 (file)
@@ -29,17 +29,17 @@ class Phone_Model_CallFilter extends Tinebase_Model_Filter_FilterGroup
     protected $_isResolved = FALSE;
     
     /**
-     * Gets the phone id filter for the first record in the given recordset
+     * Gets the phone id filter for the first record in the given array
      * 
-     * @param Tinebase_Record_RecordSet $userPhones
+     * @param array $userPhoneIds
      * @return Tinebase_Model_Filter_Abstract
      */
-    protected function _getDefaultPhoneFilter($userPhones)
+    protected function _getDefaultPhoneFilter($userPhoneIds)
     {
-        if ($userPhones->count()) {
+        if (! empty($userPhoneIds)) {
             $filter = $this->createFilter(
                 array('id' => 'defaultAdded', 'field' => 'phone_id', 'operator' => 'AND', 'value' => array(
-                    array('field' => ':id', 'operator' => 'in', 'value' => $userPhones->getId())
+                    array('field' => ':id', 'operator' => 'equals', 'value' => $userPhoneIds[0])
                 ))
             );
         } else {
@@ -66,11 +66,10 @@ class Phone_Model_CallFilter extends Tinebase_Model_Filter_FilterGroup
                 array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Core::getUser()->getId())
             ));
             
-            $userPhones = Phone_Controller_MyPhone::getInstance()->search($filter);
-            $userPhoneIds = $userPhones->getId();
+            $userPhoneIds = Phone_Controller_MyPhone::getInstance()->search($filter)->getId();
 
             if ($phoneIdFilter === NULL) {
-                $this->addFilter($this->_getDefaultPhoneFilter($userPhones));
+                $this->addFilter($this->_getDefaultPhoneFilter($userPhoneIds));
             } else {
                 $phoneId = $phoneIdFilter->getValue();
                 $phoneId = $phoneId[0]['value'];