Skip to content

Instantly share code, notes, and snippets.

@MegaphoneJon
Created November 25, 2019 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MegaphoneJon/40cb4ee82b526ac7fd62031b66b8b21d to your computer and use it in GitHub Desktop.
Save MegaphoneJon/40cb4ee82b526ac7fd62031b66b8b21d to your computer and use it in GitHub Desktop.
diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php
index 182e4fdba8..2fa668f950 100644
--- a/CRM/Export/Form/Select.php
+++ b/CRM/Export/Form/Select.php
@@ -231,11 +231,23 @@ FROM {$this->_componentTable}
$this->assign('totalSelectedRecords', $rowCount);
}
+ // If you have a large export and transfer data via $this->get() or $this->set(),
+ // it can overwhelm session storage limits. Use a temporary space.
+ $zCachePrefix = $this->get('zCachePrefix');
+ if (!$zCachePrefix) {
+ $zCachePrefix = 'CRM_Export_' . CRM_Utils_String::createRandom(16, CRM_Utils_String::ALPHANUMERIC);
+ $this->set('zCachePrefix', $zCachePrefix);
+ }
+ $zCacheTtl = 60 * 60;
+ $zCachePut = function($key, $data) use ($zCachePrefix, $zCacheTtl) {
+ Civi::cache('long')->set("{$zCachePrefix}_{$key}", gzencode(json_encode($data), 9), $zCacheTtl);
+ };
+
$this->assign('matchingContacts', $this->_matchingContacts);
- $this->set('componentIds', $this->_componentIds);
+ $zCachePut('componentIds', $this->_componentIds); // O(N)
$this->set('selectAll', $this->_selectAll);
$this->set('exportMode', $this->_exportMode);
- $this->set('componentClause', $this->_componentClause);
+ $zCachePut('componentClause', $this->_componentClause); // O(N)
$this->set('componentTable', $this->_componentTable);
}
diff --git a/CRM/Export/Form/Map.php b/CRM/Export/Form/Map.php
index 38b961ae6b..122fe1bd3c 100644
--- a/CRM/Export/Form/Map.php
+++ b/CRM/Export/Form/Map.php
@@ -215,15 +215,25 @@ class CRM_Export_Form_Map extends CRM_Core_Form {
}
}
+ // Look up info retained from previous step
+ $zCachePrefix = $this->get('zCachePrefix');
+ $zCacheGet = function($key) use ($zCachePrefix) {
+ $raw = Civi::cache('long')->get("{$zCachePrefix}_{$key}");
+ if ($raw === NULL ) {
+ throw new \CRM_Core_Exception("Export process has expired or did not begin properly. Please start over.");
+ }
+ return json_decode(gzdecode($raw));
+ };
+
//get the csv file
CRM_Export_BAO_Export::exportComponents($this->get('selectAll'),
- $this->get('componentIds'),
+ $zCacheGet('componentIds'),
(array) $this->get('queryParams'),
$this->get(CRM_Utils_Sort::SORT_ORDER),
$mappedFields,
$this->get('returnProperties'),
$this->get('exportMode'),
- $this->get('componentClause'),
+ $zCacheGet('componentClause'),
$this->get('componentTable'),
$this->get('mergeSameAddress'),
$this->get('mergeSameHousehold'),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment