Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Prevent cache overflow when querying nodes by related entities #4877

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could probably just use the array key from here? but I guess fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so, as we have two loops.

// 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