Skip to content

fix: cache the entity registry per filament panel [4.x] - #294

Merged
ManukMinasyan merged 3 commits into
4.xfrom
fix/cache-entity-registry-per-panel-4x
Nov 9, 2026
Merged

ManukMinasyan merged 3 commits into
4.xfrom
fix/cache-entity-registry-per-panel-4x

Conversation

@ManukMinasyan

@ManukMinasyan ManukMinasyan commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

This forward-ports #289 to 4.x. v4.0.0-beta.2 caches the entity registry under one key, custom_fields_entities, while discovery reads the current Filament panel's resources. So an app with several panels serves every panel the registry of whichever panel built the cache first. The other panels lose a model's resource class, its title attribute (falling back to id) and its search attributes for the full TTL.

What changed

Cherry-picks of the three #289 commits, which apply unchanged. EntityManager, EntityDiscovery, EntityServiceProvider, CustomFieldsServiceProvider and the configuration docs are identical on 4.x and the 3.x base they were written against.

  • EntityManager caches the registry per panel (custom_fields_entities:<panel id>, no-panel without a default panel), in memory and in the cache store.
  • EntityDiscovery drops its own memo, which held the first panel's resources for the life of the singleton.
  • The ttl passed to EntityConfigurator::cache() reaches the cache instead of a hardcoded 3600.
  • New custom-fields:clear-cache command forgets every panel's key, for use as a deploy step.

Behavior to know about

  • Each panel builds its own registry once per TTL. An old global key is never read again and expires on its own.
  • With caching off, nothing changes except that a manager rebuilds when the current panel changes within one process.
  • No migration, no new config key.

Tests

tests/Feature/EntityRegistryCacheTest.php (4 tests, unchanged from #289): per-panel registries whichever panel builds first, one manager across a panel switch, the configured TTL, and the clear command removing both panels' keys. They fail on 3.x before #289, and the code they cover is identical here.

Checked

On cb7422ac, with the committed composer.lock:

  • vendor/bin/pest --parallel: 936 passed, 3 todo.
  • PHPStan reports no errors, and Pint passes.
  • Rector reports 3 changes, in ImportContractConformanceTest, ImportDateFormatTest and ConsumerScopeHooksTest. A clean origin/4.x reports the same 3, and this branch touches none of those files.

Discovery builds the registry from the current panel's resources, but the cache key was shared, so a multi-panel app served every panel the registry of whichever panel built it first. The key now carries the panel id, and the configured ttl reaches the cache.
Clears the cached entity registry of every panel, so a deploy can drop a registry built from the previous configuration.
A long-lived manager, such as a queue worker running import jobs for several panels, kept serving the first panel's registry and could write it under another panel's cache key. The manager's memo is now keyed by panel id, and discovery no longer keeps its own memo.
Copilot AI balanced review requested due to automatic review settings November 8, 2026 21:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@ManukMinasyan
ManukMinasyan force-pushed the fix/cache-entity-registry-per-panel-4x branch from 3a1ae2d to cb7422a Compare November 9, 2026 11:25
@ManukMinasyan
ManukMinasyan merged commit e08c529 into 4.x Nov 9, 2026
3 checks passed
@ManukMinasyan
ManukMinasyan deleted the fix/cache-entity-registry-per-panel-4x branch November 9, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants