alleyinteractive / alleyinteractive/alley-scripts
Reduce requests in post picker
- Dominant language
- TypeScript
- Stars
- 10
- Forks
- 3
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 2
Description
### Description
In the normal flow of the post picker,
1. The user presses "Select"
2. The post picker modal opens and runs a search, which fires a REST request to the search endpoint (e.g. `/wp-json/wp/v2/search?type=post&subtype%5B0%5D=post&subtype%5B1%5D=page&page=1&_embed=1&exclude=&_locale=user`
3. The user selects a post
4. The post picker uses `usePostById()` which will then take the post ID, and run another REST API search to get the post type (e.g. `/wp-json/wp/v2/search?include=150&_locale=user`)
5. `usePostById()` uses `usePost()`, which calls `getEntityRecord()`, which will then make a REST API request to get the post object (e.g. `/wp-json/wp/v2/posts/150?context=edit&_locale=user`).
6. The preview of the post is rendered, by default with the thumbnail, title, and post type. However, the `previewRender` prop could be passed to render more data.
In most cases, the data we get back from the search in step 2 provides everything we need throughout the rest of the process, and the requests in step 4 and 5 are unnecessary. At the absolute least, the request in step 5 should be unnecessary during this flow, as the post type is included in the response in step 2.
What can we do to refactor this code to make this process more efficient?
### Use Case
Normal use of the post picker component.
Contributor guide
Assessment
This issue has not been assessed yet.