Problem/Motivation

Two leftovers in the module file, both found while auditing what this module changes outside its own endpoints. Neither is a bug today; both are the kind of thing that becomes one.

  • hook_entity_bundle_create() and hook_entity_bundle_delete() clear the whole REST plugin definition cache whenever any bundle is created or deleted anywhere on the site. The definitions do depend on which bundles exist, so an invalidation is right — but it fires for bundles this module will never serve, and a migration that creates bundles in a loop clears the cache once per bundle.
  • myrest_translatable_menu_link_uri_iterate_menu() is named exactly as an implementation of a hook belonging to a contributed module would be named. It is not one: it is a copy of that module's logic, called from this module's own menu builder. Today nothing else invokes it, but the name is an invitation for a future reader — or a future hook of that name — to make it run over every menu on the site.

Proposed resolution

  • Invalidate only when the bundle is one the module's resources declare, or when a resource declares a bundle that has just appeared; otherwise return without touching the cache.
  • Coalesce repeated invalidations within one request, so that creating twenty bundles clears the cache once.
  • Rename the helper to something that cannot be mistaken for a hook implementation, and move the logic into the service that already owns it, leaving the module file with no function of that shape.
  • Cover the first with a test that creates an unrelated bundle and asserts the definitions were not rebuilt.

Remaining tasks

Everything.

Issue fork myrest-3618930

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sergeydruua created an issue. See original summary.

  • sergeydruua committed 60591523 on 1.0.x
    Issue #3618930: Invalidate the resource definitions only for the bundles...
sergeydruua’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

sergeydruua’s picture

Status: Fixed » Closed (fixed)