Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/561: delay image generation when using the Media Inserter #569

Merged
merged 10 commits into from
Aug 21, 2023
Merged

Conversation

Sidsector9
Copy link
Member

Closes #561

Description of the Change

Adds a modified version of debounce to add delay to an already debounced callback.

How to test the Change

  1. Pull the fix branch
  2. To really see the difference, increase the delay from 700 to 2000 in this line fetch: debounce( imageFetcher, 700 ),
  3. In the media inserter, type very slowly and observe that there are no multiple AJAX calls

Changelog Entry

Fixed - Delay image generation when using the Media Inserter

Credits

Props @dkotter @Sidsector9

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@Sidsector9 Sidsector9 requested review from dkotter, jeffpaul and a team as code owners August 18, 2023 11:48
@Sidsector9 Sidsector9 removed the request for review from a team August 18, 2023 11:48

return images;
},
fetch: debounce( imageFetcher, 700 ),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to increase this delay. In my testing, I was still seeing multiple ajax requests at this point. If I increase this up to 2000 or 3000, I still occasionally saw two ajax requests but often only one and never more than two

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkotter I performed a programmatic test by simulating human input every "x" seconds.

Case 1: Debounce delay: 1000ms, typing interval: 900. Result - No ajax calls

No.ajax.mp4

Case 2: Debounce delay: 1000ms, typing interval: 1100. Result - Ajax calls for every input change

Ajax.calls.mp4

Just wanted to confirm if we should be increasing the debounce delay between 2000 - 3000ms?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here's what I get right now:

image.generation.mov

I enter a fairly simple image prompt with a fairly normal typing speed and I end up getting 7 requests before I actually finish (which at 2 cents per image and generating 3 images per request, that ends up costing 42 cents).

If I change the debounce all the way up to 3000, I get only a single request, though it takes a bit for that request to fire off:

image.generation.3000.mov

So unless I'm testing this wrong, I think we need to increase that debounce value somewhere between 2000 and 3000 to be more sure less requests will get sent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, it's the pauses a user may take after typing few words that will trigger AJAX requests. I've increased the delay to 2500ms.

@dkotter dkotter merged commit cceef5a into develop Aug 21, 2023
11 of 12 checks passed
@dkotter dkotter deleted the fix/561 branch August 21, 2023 13:34
@dkotter dkotter added this to the 2.3.0 milestone Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Look to delay image generation when using the Media Inserter
2 participants