Skip to content

Commit

Permalink
Issue #3445409 by bramtenhove: Remove expensive entity loads for the …
Browse files Browse the repository at this point in the history
…event enrollment counter
  • Loading branch information
bramtenhove committed May 8, 2024
1 parent 397a268 commit 64b0f5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function social_event_tokens($type, $tokens, array $data, array $options, Bubble
$count = count($enrollments->getEventEnrollmentsByStatus((int) $node->id(), [
EventEnrollmentInterface::INVITE_ACCEPTED_AND_JOINED,
EventEnrollmentInterface::REQUEST_APPROVED,
]));
], TRUE));
$enrollments = \Drupal::translation()->formatPlural(
$count,
':count person has enrolled',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,17 @@ public function getAllEventEnrollments($event, $ignore_all_status = FALSE) {
* Event id to search enrollments.
* @param array $filter
* Event enrollment status to be filtered.
* @param bool $ids_only
* (optional) Don't return a list of objects, but just their IDs. Defaults
* to FALSE.
*
* @return array
* Return an array of EventEnrollmentEntity.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function getEventEnrollmentsByStatus(int $event_id, array $filter): array {
public function getEventEnrollmentsByStatus(int $event_id, array $filter, bool $ids_only = FALSE): array {
// Get event-enrollment query.
$query = $this->entityTypeManager
->getStorage('event_enrollment')
Expand All @@ -239,6 +242,12 @@ public function getEventEnrollmentsByStatus(int $event_id, array $filter): array
->condition($status_group_condition)
->execute();

// If just IDs were requested we can return here without needing to do an
// expensive load for the enrollment entities.
if ($ids_only) {
return $event_nid;
}

return $this->entityTypeManager->getStorage('event_enrollment')
->loadMultiple($event_nid);
}
Expand Down

0 comments on commit 64b0f5e

Please sign in to comment.