Problem/Motivation
Hide 'Usage' tab where the bundle in context does not have any usages for any entities in the bundle. Presently the visibility of 'Usage' tab is configured by entity type, and is not backed by actual data.
Proposed resolution
Simply track whether a bundle has at least one usage, and put the values of these flags in an invalidatable cache. So when new bundles are added/removed we can simply invalidate and rebuild it.
We could have hidden the usage tab for entities if just the entity in context did not have usage, but I decided that its more useful for the tab to be present and display zero usages on the page than for it to be inexplicably missing for some entities.
Other notes
Currently Entity Usage project doesn't track bundle stats.
EU should probably track bundle in a new column in {entity_usage}, in the same manner as field tables do in order to efficiently delete data when a bundle is deleted.
In any case this optimisation can be made in another issue, there are ways to determine usage with SQL joins, though the logic is not foolproof.
Remaining tasks
Review
User interface changes
Usage tab visibility may hide automatically.
API changes
New service. Implementation introduces it but does not provide a finalised API (interface). See @internal
notes on service.
Data model changes
Makes use of cache API, so new cache table will be created automatically if using database backed caching.