Skip to content

Commit

Permalink
Merge pull request #4877 from neos/bugfix/query-cache-overflow
Browse files Browse the repository at this point in the history
BUGFIX: Prevent cache overflow when querying nodes by related entities
  • Loading branch information
Sebobo authored Feb 7, 2024
2 parents 043de3f + 3a2e9a3 commit 38dc075
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1710,24 +1710,29 @@ protected function buildQueryBuilderForRelationMap($relationMap)
$constraints = [];
$parameters = [];

// Use a counter to avoid parameter name conflicts and limit query metadata cache entries to the maximum number of relations
$identifierIndex = 0;

foreach ($relationMap as $relatedObjectType => $relatedIdentifiers) {
foreach ($relatedIdentifiers as $relatedIdentifier) {
// entity references like "__identifier": "so-me-uu-id"
$constraints[] = '(LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :entity' . md5($relatedIdentifier) . ' )';
$parameters['entity' . md5($relatedIdentifier)] = '%"__identifier": "' . strtolower($relatedIdentifier) . '"%';
$constraints[] = '(LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :entity' . $identifierIndex . ' )';
$parameters['entity' . $identifierIndex] = '%"__identifier": "' . strtolower($relatedIdentifier) . '"%';

// asset references in text like "asset://so-me-uu-id"
$constraints[] = '(LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :asset' . md5($relatedIdentifier) . ' )';
$constraints[] = '(LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :asset' . $identifierIndex . ' )';
switch ($this->entityManager->getConnection()->getDatabasePlatform()->getName()) {
case 'postgresql':
$parameters['asset' . md5($relatedIdentifier)] = '%asset://' . strtolower($relatedIdentifier) . '%';
$parameters['asset' . $identifierIndex] = '%asset://' . strtolower($relatedIdentifier) . '%';
break;
case 'sqlite':
$parameters['asset' . md5($relatedIdentifier)] = '%asset:\/\/' . strtolower($relatedIdentifier) . '%';
$parameters['asset' . $identifierIndex] = '%asset:\/\/' . strtolower($relatedIdentifier) . '%';
break;
default:
$parameters['asset' . md5($relatedIdentifier)] = '%asset:\\\\/\\\\/' . strtolower($relatedIdentifier) . '%';
$parameters['asset' . $identifierIndex] = '%asset:\\\\/\\\\/' . strtolower($relatedIdentifier) . '%';
}

$identifierIndex++;
}
}

Expand Down

0 comments on commit 38dc075

Please sign in to comment.