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 | Infinite loop when re-scanning image #630

Closed
wants to merge 1 commit into from

Conversation

sksaju
Copy link
Member

@sksaju sksaju commented Dec 4, 2023

Description of the Change

Closes #623

How to test the Change

Changelog Entry

Added - New feature
Changed - Existing functionality
Deprecated - Soon-to-be removed feature
Removed - Feature
Fixed - Bug fix
Security - Vulnerability

Credits

Props @username, @username2, ...

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.

@sksaju sksaju requested review from dkotter, jeffpaul and a team as code owners December 4, 2023 15:14
@jeffpaul jeffpaul added this to the 2.5.0 milestone Dec 4, 2023
if ( in_array( 'caption', $enabled_fields, true ) ) {
$excerpt = get_the_excerpt( $attachment_id );

if ( in_array( 'caption', $enabled_fields, true ) && $excerpt !== $captions[0]->text ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this truly fixes the issue, though I didn't test. But in the scenario where an image doesn't have an excerpt set and you trigger the generation of one, this check will return false (which is correct) and wp_update_post will be called, which then triggers this function to be called again. The second time it runs this code check will return true and so things won't execute again but ideally we should never execute this code again in the first place.

I'd suggest instead of doing this we remove the hook if we make it to the wp_update_post part, so it doesn't trigger again in that execution:

remove_action( 'edit_attachment', [ $this, 'maybe_rescan_image' ] );

Copy link
Collaborator

Choose a reason for hiding this comment

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

In addition to the above, I think there are a few other places where we have the same issue (again, just looking at the code, didn't test this).

I see a wp_update_post call just a few lines below this (line 814) and then our OCR processing I think will have the same issue as we call wp_update_post in our generate_ocr_data method, which can be triggered by the edit_attachment hook

@jeffpaul jeffpaul modified the milestones: 2.5.0, 2.6.0 Dec 6, 2023
@jeffpaul jeffpaul removed their request for review January 16, 2024 15:29
@dkotter
Copy link
Collaborator

dkotter commented Jan 31, 2024

Thanks for all the work here @sksaju! Due to the major refactoring we just merged in, I'm going to close this PR out in favor of #677.

@dkotter dkotter closed this Jan 31, 2024
@dkotter dkotter removed this from the 3.1.0 milestone Jan 31, 2024
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.

Infinite loop when re-scanning image
3 participants