Skip to content

Commit

Permalink
CiviImport - Remove redundant caching
Browse files Browse the repository at this point in the history
APIv4 now caches the output of all SpecProviders, so there is no need for them to use internal caching.
  • Loading branch information
colemanw committed Jan 23, 2024
1 parent 235963e commit 00bcb3e
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions ext/civiimport/Civi/Api4/Import/ImportSpecProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function modifySpec(RequestSpec $spec): void {
* @inheritDoc
*/
public function applies($entity, $action): bool {
return strpos($entity, 'Import_') === 0;
return str_starts_with($entity, 'Import_');
}

/**
Expand All @@ -82,18 +82,14 @@ public function applies($entity, $action): bool {
* @throws \CRM_Core_Exception
*/
public function getJobType(RequestSpec $spec): array {
if (!isset(\Civi::$statics[__CLASS__][$spec->getEntity()])) {
// CheckPermissions does not reach us here - so we will have to rely on earlier permission filters.
$userJobID = substr($spec->getEntity(), (strpos($spec->getEntity(), '_') + 1));
$userJob = UserJob::get(FALSE)
->addWhere('id', '=', $userJobID)
->addSelect('metadata', 'job_type', 'created_id')
->execute()
->first();
\Civi::$statics[__CLASS__][$spec->getEntity()] = CRM_Core_BAO_UserJob::getType($userJob['job_type']);
}

return \Civi::$statics[__CLASS__][$spec->getEntity()];
// CheckPermissions does not reach us here - so we will have to rely on earlier permission filters.
[, $userJobID] = explode('_', $spec->getEntity(), 2);
$userJob = UserJob::get(FALSE)
->addWhere('id', '=', $userJobID)
->addSelect('metadata', 'job_type', 'created_id')
->execute()
->first();
return CRM_Core_BAO_UserJob::getType($userJob['job_type']);
}

}

0 comments on commit 00bcb3e

Please sign in to comment.