Problem/Motivation
I noticed that on some pages which had a lot of entities using domain access, my site was taking a huge performance hit. As a result, the site was slowed to a crawl. I investigated this using blackfire, and determined that among other issues, the call to the database were slowing the site down. One case was checking the router_rebuild lock on every call to domain_entity_query_alter() creates a database query. Instead of checking this every time it makes sense to only check the lock when we are actually checking access for an entity type which is enabled for domain access, since that data is complied on the first run, and cached statically.
TBH I'm slightly unsure if the lock check is entirely necessary, but from the code, its not entirely clear what the motivation was for adding it, so I don't think removing it makes sense.
Steps to reproduce
Enable domain access for menu items (menu_link_content), and reload the page as an admin. The site should slow down significantly. (In order to actually enable domain access on menu items, special work is required to inject the field into the edit ui. But this isn't required for this module.)
Proposed resolution
Move the call to the lock check so its made only when necessary (once we know the query is for a domain access controlled entity type) in order to not waste time with the query.
Remaining tasks
Merge the fix.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork domain_entity-3249712
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
Comment #3
richgerdesComment #6
delta commentedComment #7
delta commentedreleased in https://www.drupal.org/project/domain_entity/releases/8.x-1.0-beta5
thank you