Optimise proximity custom search, by reducing addGeocodingData fn call
authorMonish Deb <deb.monish@gmail.com>
Mon, 24 Aug 2020 12:18:25 +0000 (17:48 +0530)
committerMonish Deb <deb.monish@gmail.com>
Mon, 24 Aug 2020 12:18:25 +0000 (17:48 +0530)
CRM/Contact/Form/Search/Custom/Proximity.php

index 34026c06de81f75eabe65e691b85df004bbdacf1..8d211aafcf7b5087a8fdcc6eb588d86c8baa5cbc 100644 (file)
@@ -19,9 +19,6 @@
  */
 class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
 
-  protected $_latitude = NULL;
-  protected $_longitude = NULL;
-  protected $_distance = NULL;
   protected $_aclFrom = NULL;
   protected $_aclWhere = NULL;
 
@@ -39,21 +36,6 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C
     unset($this->_formValues['uf_group_id']);
     unset($this->_formValues['component_mode']);
     unset($this->_formValues['operator']);
-
-    if (!empty($this->_formValues)) {
-      // add the country and state
-      self::addGeocodingData($this->_formValues);
-      $this->_latitude = $this->_formValues['geo_code_1'];
-      $this->_longitude = $this->_formValues['geo_code_2'];
-
-      if ($this->_formValues['prox_distance_unit'] == "miles") {
-        $conversionFactor = 1609.344;
-      }
-      else {
-        $conversionFactor = 1000;
-      }
-      $this->_distance = $this->_formValues['distance'] * $conversionFactor;
-    }
     $this->_group = $this->_formValues['group'] ?? NULL;
 
     $this->_tag = $this->_formValues['tag'] ?? NULL;
@@ -192,6 +174,10 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C
       $isCountOnly = TRUE;
     }
 
+    if (empty($this->_formValues['geo_code_1']) ||  empty($this->_formValues['geo_code_2'])) {
+      self::addGeocodingData($this->_formValues);
+    }
+
     $searchParams = [
       ['prox_distance_unit', '=', $this->_formValues['prox_distance_unit'], 0, 0],
       ['prox_distance', '=', $this->_formValues['distance'], 0, 0],