Skip to content

Commit

Permalink
Pull "info" apart to separate settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Apr 9, 2024
1 parent 87f1cbd commit f89a4c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/EventSubscriber/EmbargoJoinProcessorEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public function preQuery(PreQueryEvent $event) : void {
return;
}

$query_info = $search_api_query->getOption('embargo_join_processor');
/** @var \Drupal\embargo\IpRangeInterface[] $ip_range_entities */
$ip_range_entities = $query_info['ip_ranges'];
$queries = $search_api_query->getOption('embargo_join_processor__queries', []);

if (!$queries) {
return;
}

$backend = $search_api_query->getIndex()->getServerInstance()->getBackend();
assert($backend instanceof SolrBackendInterface);
Expand All @@ -99,7 +101,10 @@ public function preQuery(PreQueryEvent $event) : void {
assert($solarium_query instanceof SolariumSelectQuery);
$helper = $solarium_query->getHelper();

foreach ($query_info['queries'] as $type => $info) {
/** @var \Drupal\embargo\IpRangeInterface[] $ip_range_entities */
$ip_range_entities = $search_api_query->getOption('embargo_join_processor__ip_ranges', []);

foreach ($queries as $type => $info) {
$solarium_query->createFilterQuery([
'key' => "embargo_join:{$type}",
'query' => strtr(
Expand Down
14 changes: 6 additions & 8 deletions src/Plugin/search_api/processor/EmbargoJoinProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,31 +247,28 @@ public function preprocessSearchQuery(QueryInterface $query) : void {
return;
}

$info = [
'queries' => [],
];
$queries = [];

if (in_array('entity:node', $this->index->getDatasourceIds())) {
$info['queries']['node'] = [
$queries['node'] = [
'data sources' => ['entity:node'],
'path' => 'embargo_node__node',
];
}
if ($intersection = array_intersect($this->index->getDatasourceIds(), ['entity:media', 'entity:file'])) {
$info['queries']['file'] = [
$queries['file'] = [
'data sources' => $intersection,
'path' => 'embargo_node__file',
];
}

if (!$info['queries']) {
if (!$queries) {
return;
}

/** @var \Drupal\embargo\IpRangeInterface[] $ip_range_entities */
$ip_range_entities = $this->entityTypeManager->getStorage('embargo_ip_range')
->getApplicableIpRanges($this->requestStack->getCurrentRequest()->getClientIp());
$info['ip_ranges'] = $ip_range_entities;

$query->addCacheContexts([
// Caching by groups of ranges instead of individually should promote
Expand All @@ -291,7 +288,8 @@ public function preprocessSearchQuery(QueryInterface $query) : void {
}

$query->addTag('embargo_join_processor');
$query->setOption('embargo_join_processor', $info);
$query->setOption('embargo_join_processor__ip_ranges', $ip_range_entities);
$query->setOption('embargo_join_processor__queries', $queries);
}

}

0 comments on commit f89a4c9

Please sign in to comment.