compucorp / uk.co.compucorp.civicrm.pivotreport

CiviCRM Pivot table reporting solution
Other
8 stars 13 forks source link

GSSPRT-148: Decrease the rows returned for Prospect report cache #138

Closed lisandro-compucorp closed 2 years ago

lisandro-compucorp commented 2 years ago

Overview

This PR solves a problem generating the cache for the prospect reports. The process of cache generation was stuck on a percentage less than 100%.

Before

While running the "Refresh All Pivot Reports", the action get stopped, because of a timeout error in one of the Ajax request performed:

Screen Shot 2021-09-23 at 16 04 13

After

The action finishes without errors:

Screen Shot 2021-09-23 at 16 24 56

Technical Details

The timeout observed is in one of the requests to the Prospect API (with Js library), for getting a set of results in order to create the report cache. For solving this, without having to think about query optimization, we can use the constant defined on CRM_PivotData_AbstractData class named ROWS_API_LIMIT. This indicates the number of results to be queried on every call to CiviCRM API, for each entity. A lower number could speedup the query time, and the result will be the same, since the calls are performed one after the other until there is no more results. We can override that value for the Prospect entity, in CRM_PivotData_DataProspect class, which is the one with performance problems. The same was done before with the Activity related class. Using 500 instead of 1000 probed to solve the problem. Note: The query could be working slowly now since we have recently added an extra condition to the where clause on Prospects. Nevertheless, in the environments where this fail (which are not production environments) the query was also timing out before this change.