Skip to content

Look to delay image generation when using the Media Inserter #561

@dkotter

Description

@dkotter

Is your enhancement related to a problem? Please describe.

In #535, we added an integration into the Media Inserter that allows you to generate and insert images straight from that inserter. At the moment, the code that added the ability to interact with this Media Inserter is only in the Gutenberg plugin (assuming this will end up in WordPress 6.4) and we only have the ability to define the fetch function.

What this means is that as someone types in their image prompt, Gutenberg itself will slightly debounce this request (currently at 250ms) before calling our custom fetch function. In reality, the debounce here is so small that as someone types in their image prompt, almost certainly we'll end up hitting the OpenAI API multiple times (and as such, be charged for each of those requests).

I had tried adding our own debouncing around this fetch function but I couldn't get it to work, I think because this function is already being debounced by Gutenberg itself. I see a few possibilities we could pursue here:

  1. Continue investigating if we can add our own debouncing here, setting that to something higher to increase the likelihood that we only send a request once a user is truly done typing
  2. Open an issue on the Gutenberg side to see if we could get an option added where you could choose between having search triggered on type or search triggered on a button submit, which the latter would solve our needs
  3. Open an issue on the Gutenberg side to see if we can make the current debounce value filterable so we can increase that. Won't definitively solve the problem but we can try increasing that value high enough that it should solve it for most

Not sure how receptive the Gutenberg team will be to changes with this component but I do think either option would be useful for anyone that wants to integrate a 3rd party service with this Media Inserter, so not something that just helps ClassifAI.

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions