#3612675: Preserve access cacheability for empty-page search counts
Fixes #3612675.
What and why
Empty result pages still expose the access-filtered total through meta.count. Without any returned entities to contribute access cacheability, responses can share cache keys across accounts whose totals differ.
- Merge the executed query's cacheability into the response, preserving datasource list cache contexts such as
user.node_grants:view. - Explicitly vary by
user.permissions, since node-grant contexts alone do not distinguish differentaccess contentpermissions when no grants module is enabled. - Add self-contained kernel regression coverage with a real database-backed Search API index and the Content access processor. The tests compare Drupal-generated cache-context keys across accounts after verifying that fresh empty-page responses have different totals.
Verification
Tested against the patched upstream 8.x-1.x resource source in a Drupal 11.4 / PHP 8.4 environment with Search API 1.43 and JSON:API Resources 1.8:
| Source variant | Permission isolation | Node-grant isolation |
|---|---|---|
| Unpatched | Fails | Fails |
| Query dependency only | Fails | Passes |
| Permission context only | Passes | Fails |
| Both additions | Passes | Passes |
The node-grant scenario uses accounts with identical permissions but different grants, so the permission context cannot hide a missing query dependency.
- Full fix: 2 tests, 28 assertions passed.
- PHPCS (
Drupal,DrupalPractice) passed for both changed files. - PHP syntax check passed for the resource.
The module's full functional suite and older supported Drupal versions have not been run locally; upstream CI still needs to verify those environments.
Related work
#3612674 (closed) / !25 (merged) also merges successful-query cacheability while addressing cached backend errors. That part overlaps; this MR leaves error handling unchanged and adds the permission context plus access-boundary regression coverage.