FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Remove additional image backup sources & sizes files when attachment deleted by mehulkaklotar · Pull Request #411 · WordPress/performance · GitHub

Remove additional image backup sources & sizes files when attachment deleted - #411

Merged
felixarntz merged 5 commits into
trunkfrom
remove/backup-sources-files
Jul 7, 2022
Merged

Remove additional image backup sources & sizes files when attachment deleted#411
felixarntz merged 5 commits into
trunkfrom
remove/backup-sources-files

Conversation

mehulkaklotar commented Jul 1, 2022
edited
Loading

Copy link
Copy Markdown
Member

Summary

Fixes #375

Relevant technical choices

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

mehulkaklotar added [Focus] Images [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) labels Jul 1, 2022
mehulkaklotar added this to the 1.3.0 milestone Jul 1, 2022
mehulkaklotar self-assigned this Jul 1, 2022
mehulkaklotar added the [Type] Bug An existing feature is broken label Jul 1, 2022
mehulkaklotar marked this pull request as ready for review July 4, 2022 11:47

mitogh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Changes look solid to me (great work). Question looking into these changes, are we expecting to delete the meta fields as well created by the plugin if the image is deleted such as:

  • _wp_attachment_backup_sources

And any other custom meta associated to an image, or those are deleted when the attachment ID is effectively deleted from within the DB?

Copy link
Copy Markdown
Member Author

@mitogh Meta fields are deleted when attachment ID is deleted. so we don't need to do anything to delete them.

mitogh commented Jul 5, 2022

Copy link
Copy Markdown
Member

Thanks @mehulkaklotar makes sense.

Comment on lines +344 to +348
$backup_sources = get_post_meta( $attachment_id, '_wp_attachment_backup_sources', true );
$this->assertEmpty( $backup_sources );

$backup_sizes = get_post_meta( $attachment_id, '_wp_attachment_backup_sizes', true );
$this->assertEmpty( $backup_sizes );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The PR looks good to me.

One question for the unit test: When the attachment is deleted using the wp_delete_attachment function, it also removes the meta associated with it, so it's worthwhile to check the post meta after it. What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, @mukeshpanchal27 We are checking after deleting attachment here that post meta is not found by asserting it is empty.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this currently is only checking that the backup meta is empty, not that the original attachment meta is deleted.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

we only add these two backup meta from the plugin, so we just need to check if these two meta is deleted. To check them deleted or not, we need to assert that it is empty when we get them using get_post_meta function which returns an empty string if a valid but non-existing post ID is passed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I personally think we should remove the checks for the post meta being empty. The post metadata is being deleted by core, so what we're testing with those two assertions is core, not our own logic. I guess it doesn't hurt having them, but if we have them here, we may also add a ton more for core tests - I think that's a bit beyond the point of unit tests, they should be for our plugin code, not the core code we're integrating with.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Removed the post meta assertions for the plugin tests.

adamsilverstein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Overall looks good - left some questions. I'm going to test this locally to verify the data handling works as expected as well as verifying -scaled or -rotated image handling is correct

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar Mostly looks great! I left just a few minor comments.

Comment on lines +333 to +337
$backup_sources = get_post_meta( $attachment_id, '_wp_attachment_backup_sources', true );
$this->assertNotEmpty( $backup_sources );

$backup_sizes = get_post_meta( $attachment_id, '_wp_attachment_backup_sizes', true );
$this->assertIsArray( $backup_sizes );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why not use the same assertions for both? Shouldn't they both be non-empty arrays? Not a big deal, but this just struck me as a bit odd.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, right, added both assertions for not empty and is array.

Comment on lines +344 to +348
$backup_sources = get_post_meta( $attachment_id, '_wp_attachment_backup_sources', true );
$this->assertEmpty( $backup_sources );

$backup_sizes = get_post_meta( $attachment_id, '_wp_attachment_backup_sizes', true );
$this->assertEmpty( $backup_sizes );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I personally think we should remove the checks for the post meta being empty. The post metadata is being deleted by core, so what we're testing with those two assertions is core, not our own logic. I guess it doesn't hurt having them, but if we have them here, we may also add a ton more for core tests - I think that's a bit beyond the point of unit tests, they should be for our plugin code, not the core code we're integrating with.

felixarntz changed the title Remove backup sources & sizes files when attachment deleted Remove additional image backup sources & sizes files when attachment deleted Jul 6, 2022

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks @mehulkaklotar, this looks great!

felixarntz merged commit 044a8f2 into trunk Jul 7, 2022
felixarntz deleted the remove/backup-sources-files branch July 7, 2022 15:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebP images not deleted when saved in backend after edit

5 participants


Back | FazBrowse Home | New Git URL