Skip to content

Commit

Permalink
Fix up the direction of multiplicity with the values.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Apr 9, 2024
1 parent 1e5dddc commit 039969e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
24 changes: 15 additions & 9 deletions src/EventSubscriber/EmbargoJoinProcessorEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,22 @@ public function preQuery(PreQueryEvent $event) : void {
$backend = $search_api_query->getIndex()->getServerInstance()->getBackend();
assert($backend instanceof SolrBackendInterface);
$map = $backend->getSolrFieldNames($search_api_query->getIndex());
$get_field_name = function (?string $datasource_id, string $property_path) use ($search_api_query, $map) {
$fields = $this->fieldsHelper->filterForPropertyPath(
$search_api_query->getIndex()->getFieldsByDatasource($datasource_id),
$datasource_id,
$property_path,
);
/** @var \Drupal\search_api\Item\FieldInterface $field */
$field = reset($fields);
$memoized_map = [];
$get_field_name = function (?string $datasource_id, string $property_path) use ($search_api_query, $map, &$memoized_map) {
$key = "{$datasource_id}__{$property_path}";
if (!isset($memoized_map[$key])) {
$fields = $this->fieldsHelper->filterForPropertyPath(
$search_api_query->getIndex()->getFieldsByDatasource($datasource_id),
$datasource_id,
$property_path,
);
/** @var \Drupal\search_api\Item\FieldInterface $field */
$field = reset($fields);

return $map[$field->getFieldIdentifier()];
$memoized_map[$key] = $map[$field->getFieldIdentifier()];
}

return $memoized_map[$key];
};

$solarium_query = $event->getSolariumQuery();
Expand Down
14 changes: 12 additions & 2 deletions src/Plugin/search_api/processor/EmbargoJoinProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ protected function doAddNodeField(ItemInterface $item, EntityInterface $entity)
protected function doAddEmbargoField(ItemInterface $item, EntityInterface $entity) : void {
assert($entity instanceof EmbargoInterface);
$paths = match ($entity->getEmbargoType()) {
EmbargoInterface::EMBARGO_TYPE_FILE => ['embargo_node__file', 'embargo_node__node'],
EmbargoInterface::EMBARGO_TYPE_NODE => ['embargo_node__node'],
EmbargoInterface::EMBARGO_TYPE_FILE => ['embargo_node__file'],
EmbargoInterface::EMBARGO_TYPE_NODE => ['embargo_node__node', 'embargo_node__file'],
};

$fields = $item->getFields(FALSE);
Expand Down Expand Up @@ -274,8 +274,18 @@ public function preprocessSearchQuery(QueryInterface $query) : void {
}

$query->addCacheContexts([
// Caching by groups of ranges instead of individually should promote
// cacheability.
'ip.embargo_range',
// Exemptable users, so need to deal with them.
'user',
]);
// Embargo dates deal with granularity to the day.
$query->mergeCacheMaxAge(24 * 3600);

/** @var \Drupal\Core\Entity\EntityTypeInterface $embargo_type */
$embargo_type = $this->entityTypeManager->getDefinition('embargo');
$query->addCacheTags($embargo_type->getListCacheTags());

$query->addTag('embargo_join_processor');
$query->setOption('embargo_join_processor', $info);
Expand Down

0 comments on commit 039969e

Please sign in to comment.