Commit 50902be7 authored by jaapjansma's avatar jaapjansma
Browse files

fixed merge conflict

parents f7c6c569 eac84b30
......@@ -6,6 +6,24 @@
* it is now also possible to output a data processor on CiviCRMs dahsboard.
* Added field outputs for simple calculations (substract and total).
# Version 1.0.6
* Performance improvement by caching the data processor and the api calls.
# Version 1.0.5
* Added error handling to importer
* Added sort in Manage data processor screen
# Version 1.0.4
* Fixed issue with activity search and actions after the search when the actions are run on all records.
# Version 1.0.3
* Fixed issue with date filters.
>>>>>>> origin/performance
# Version 1.0.2
* Fixed bug #11 (Fatal error clone on non object)
......
......@@ -56,6 +56,11 @@ class CRM_Dataprocessor_BAO_DataProcessor extends CRM_Dataprocessor_DAO_DataProc
* @throws \Exception
*/
public static function dataProcessorToClass($dataProcessor) {
$cache_key = 'dataprocessor_'.$dataProcessor['id'];
$cache = CRM_Dataprocessor_Utils_Cache::singleton();
if ($dataProcessorClass = $cache->get($cache_key)) {
return $dataProcessorClass;
}
$factory = dataprocessor_get_factory();
$dataProcessorClass = $factory->getDataProcessorTypeByName($dataProcessor['type']);
$sources = civicrm_api3('DataProcessorSource', 'get', array('data_processor_id' => $dataProcessor['id'], 'options' => array('limit' => 0)));
......@@ -105,6 +110,7 @@ class CRM_Dataprocessor_BAO_DataProcessor extends CRM_Dataprocessor_DAO_DataProc
}
}
}
$cache->set($cache_key, $dataProcessorClass);
return $dataProcessorClass;
}
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_Dataprocessor_Utils_Cache {
/**
* @var CRM_DataProcessor_Utils_Cache
*/
private static $singleton;
/**
* @var \CRM_Utils_Cache_Interface
*/
protected $cache;
private function __construct() {
$this->cache = \CRM_Utils_Cache::create([
'name' => 'dataprocessor',
'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
'prefetch' => FALSE,
]);
}
/**
* @return \CRM_DataProcessor_Utils_Cache
*/
public static function singleton() {
if (!self::$singleton) {
self::$singleton = new CRM_DataProcessor_Utils_Cache();
}
return self::$singleton;
}
/**
* @param $key
* @param null $default
*
* @return mixed
*/
public function get($key, $default=NULL) {
return $this->cache->get($key, $default);
}
/**
* @param $key
* @param $value
* @param null $ttl
*
* @return bool
*/
public function set($key, $value, $ttl=NULL) {
return $this->cache->set($key, $value, $ttl);
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\DataSpecification;
class MaxFieldSpecification extends FieldSpecification {
/**
* Returns the select statement for this field.
* E.g. COUNT(civicrm_contact.id) AS contact_id_count
*
* @param String $table_alias
* @return string
*/
public function getSqlSelectStatement($table_alias) {
return "MAX(`{$table_alias}`.`{$this->name}`) AS `{$this->alias}`";
}
}
\ No newline at end of file
......@@ -68,11 +68,11 @@ class GroupsOfContactFieldOutputHandler extends AbstractFieldOutputHandler {
public function initialize($alias, $title, $configuration) {
$this->outputFieldSpecification = new FieldSpecification($alias, 'String', $title, null, $alias);
$this->contactIdSource = $this->dataProcessor->getDataSourceByName($configuration['datasource']);
if (!$this->dataSource) {
if (!$this->contactIdSource) {
throw new DataSourceNotFoundException(E::ts("Field %1 requires data source '%2' which could not be found. Did you rename or deleted the data source?", array(1=>$title, 2=>$configuration['datasource'])));
}
$this->contactIdField = $this->contactIdSource->getAvailableFields()->getFieldSpecificationByName($configuration['field']);
if (!$this->inputFieldSpec) {
if (!$this->contactIdField) {
throw new FieldNotFoundException(E::ts("Field %1 requires a field with the name '%2' in the data source '%3'. Did you change the data source type?", array(
1 => $title,
2 => $configuration['field'],
......
......@@ -16,10 +16,19 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use \CRM_Dataprocessor_ExtensionUtil as E;
class Api implements OutputInterface, API_ProviderInterface, EventSubscriberInterface{
class Api implements OutputInterface, API_ProviderInterface, EventSubscriberInterface {
public function __construct() {
/**
* @var \CRM_Utils_Cache_Interface
*/
protected $cache;
public function __construct() {
$this->cache = \CRM_Utils_Cache::create([
'name' => 'dataprocessor_api',
'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
'prefetch' => true,
]);
}
/**
......@@ -174,6 +183,13 @@ class Api implements OutputInterface, API_ProviderInterface, EventSubscriberInte
}
protected function getFields($entity, $params) {
$cacheKey = 'getfields_'.strtolower($entity);
if (isset($params['action'])) {
$cacheKey .= '_'.strtolower($params['action']);
}
if ($cache = $this->cache->get($cacheKey)) {
return $cache;
}
$types = \CRM_Utils_Type::getValidTypes();
$types['Memo'] = \CRM_Utils_Type::T_TEXT;
$fields = array();
......@@ -250,6 +266,7 @@ class Api implements OutputInterface, API_ProviderInterface, EventSubscriberInte
$fields[$fieldSpec->alias] = array_merge($fields[$fieldSpec->alias], $field);
}
}
$this->cache->set($cacheKey, $fields);
return $fields;
}
......@@ -326,7 +343,12 @@ class Api implements OutputInterface, API_ProviderInterface, EventSubscriberInte
if (strtolower($dao->api_count_action) == $apiRequest['action']) {
$isCountAction = TRUE;
}
$dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $dao->data_processor_id));
$cache_key = 'data_processor_id_'.$dao->data_processor_id;
if (! ($dataProcessor = $this->cache->get($cache_key)) ){
$dataProcessor = civicrm_api3('DataProcessor', 'getsingle', ['id' => $dao->data_processor_id]);
$this->cache->set($cache_key, $dataProcessor);
}
$dataProcessorClass = \CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($dataProcessor);
$params = $apiRequest['params'];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment