Problem/Motivation
The Views analyzer (modules/audit_views/src/Plugin/AuditAnalyzer/ViewsAnalyzer.php) raises CACHE_TAG_GENERIC on tag-cached displays that filter by bundle, suggesting bundle-specific tags (node_list:article...) instead of the generic list tag (node_list). The bundles come from extractBundlesFromFilters(), which only reads the filter's value and ignores the operator and the exposed settings.
That is only right when the filter really restricts the results to those bundles. It is wrong in these cases, all verified against core's InOperator / FilterPluginBase::acceptExposedInput():
- Operator "not in": the value lists the EXCLUDED bundles. The analyzer suggests tags for exactly the bundles the view never shows, and nothing for the ones it does show.
- Exposed and not required: when the visitor chooses "- Any -", acceptExposedInput() returns FALSE and the filter is removed from the query, so every bundle is listed. This also applies with "Limit list to selected items" (expose.reduce); the InOperator exception for "All" depends on expose.limit, which core never sets.
- Exposed, required, not reduced: the visitor can select any bundle.
- Grouped exposed filters: the bundles depend on the selected group.
In all these cases the visitor can see content of any bundle, so the generic list tag is the CORRECT tag: following the recommendation would make the cache miss new content of the other bundles. The only alternative that satisfies the analyzer is to list every bundle as a tag, which is equivalent to the generic tag and has to be maintained by hand whenever a bundle is added.
Steps to reproduce
1. Create a content view with tag-based cache and a "Content type" filter, exposed and optional, with Article and Basic page preselected.
2. Run drush audit:run views --format=json.
3. CACHE_TAG_GENERIC is reported, suggesting node_list:article and node_list:page, although "- Any -" lists every content type.
Proposed resolution
In extractBundlesFromFilters(), only take the bundles of a bundle filter that restricts the results to its value (new helper filterFixesBundles()):
- operator "in" (the default) or "=";
- not exposed, or exposed, not grouped, required and reduced ("Limit list to selected items").
Other bundle filters contribute no bundles, so the display is not reported as CACHE_TAG_GENERIC and the entity label no longer lists bundles the view does not restrict to.
Remaining tasks
- Add filterFixesBundles() and use it in extractBundlesFromFilters().
- Unit test with a data provider on detectEntityAndBundles(): not exposed => bundles; "not in" => none; exposed optional (with and without reduce) => none; exposed required not reduced => none; exposed required reduced => bundles; grouped => none.
User interface changes
Displays with these filters no longer get a CACHE_TAG_GENERIC warning, and their entity column shows the entity type without a bundle list.
API changes
None.
Data model changes
None.
Comments
Comment #3
trebormc