Problem/Motivation
Caching is disabled on the REST resource because an object not implementing the CacheableDependencyInterface is passed to addCacheableDependency. In fact, the object being passed is currently an array.
------ ---------------------------------------------------------------------
Line src/Plugin/rest/resource/VertexAISearchResource.php
------ ---------------------------------------------------------------------
150 Calling addCacheableDependency($object) when $object does not
implement CacheableDependencyInterface effectively disables caching
and should be avoided.
🪪 cacheable.dependency
Steps to reproduce
This issue is being found by phpstan in the pipelines for any MRs.
Proposed resolution
Create a CacheableMetadata object and add the url.query_args context to it.
Pass this to the resourceResponse cacheable dependency.
// Create a cacheable metadata object.
$cacheMetadata = new CacheableMetadata();
// Add the query arguments context so variations cache correctly.
$cacheMetadata->addCacheContexts(['url.query_args']);
$resourceResponse->addCacheableDependency($cacheMetadata);
Comments
Comment #2
timozura commentedComment #4
timozura commentedNeeded to fix as it was preventing clean pipeline runs for additional MRs.
Fix added, merged into dev.