Increase route build speed.

Created on 30 October 2024, 23 days ago

Problem/Motivation

Currently during a route rebuild the module loops through each view, then gets the entity type and bundles for the view, and the grabs the resource names for each entity/bundle combination:

        $resource_types = array_map(function ($bundle) use ($entity_type) {
          return $this->resourceTypeRepository->get($entity_type, $bundle)->getTypeName();
        }, $bundles);

During normal usage this works fine, but during database updates it causes a massive slowdown. If a module does any sort of update that requires a route rebuild, the module can take over 45 minutes to complete on a moderately sized site (46 views with `13 content types in my case). This is because during database updates the cache backend is switched to UpdateBackend, which prevents cache writes. This makes it so that each call to the resourcetype repository involves it rebuilding its cache, which slows down things considerably.

Proposed resolution

The easiest fix for now would be to hold onto the $resources_types returned for each entity type, and use them for any other views that share that entity type. This way if you have 10 views that are node based, for example, you're only paying once for the performance hit to get the resources names. During normal use it doesn't make a huge difference but during database updates you get a massive performance increase. That's what the attached patch does.

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jacobbell84

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jacobbell84
  • πŸ‡¨πŸ‡­Switzerland jlenni

    Thank you, Jake, for the patch! This is already a life saver

    Identifying the issue was quite challenging - unexpectedly, updb during deployment took 26 minutes, leaving me completely in the dark.

    Would it be beneficial if we could limit the processing to views where "Exposed via JSON" is enabled?
    Currently, as I see it, all active views are being processed, regardless of whether "Exposed via JSON" is enabled or disabled.

Production build 0.71.5 2024