Skip to content

Unable to save post with AQL on site with many posts #157

@trevormills-xwp

Description

@trevormills-xwp

I'm using the most recent version - 4.4.0.

Minimal reproduce steps:

  • Site must have 1000's of posts on it
  • Create a new post
  • Add AQL block
  • Change Query Type from Default to Custom
  • Attempt to hit Publish. It looks like it's working, but never actually completes.

The source of the issue is this block of code in src/components/post-exclude-controls.js:

	// Get the posts for all post types used in the query.
	const posts = useSelect(
		( select ) => {
			const { getEntityRecords } = select( 'core' );

			// Fetch posts for each post type and combine them into one array
			return [ ...multiplePosts, postType ].reduce(
				( accumulator, type ) => {
					// Depending on the number of posts this could take a while, since we can't paginate here
					const records = getEntityRecords( 'postType', type, {
						per_page: -1,
					} );
					return [ ...accumulator, ...( records || [] ) ];
				},
				[]
			);
		},
		[ postType, multiplePosts ]
	);

With per_page set to -1, core middleware changes that to a paged run of queries with per_page: 100, as page=1, page=2, ...etc. On the site I'm working on, each query takes many seconds to complete, and the save action in the editor will not complete until all pages have been retrieved. This affects autosaves as well as user initiated saves.

Interestingly, if you do the same reproduce steps on a page as opposed to a post, the save action completes, even though that paging run remains ongoing.

Besides causing an issue saving the post, this is also a burden on the server having to unnecessarily deal with a string of requests that take many seconds to complete.

My expectation would be that it only fetches posts if there's a search string to narrow down the list of results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions