Make WordPress Core

Opened 6 months ago

Closed 5 months ago

Last modified 5 months ago

#62658 closed enhancement (fixed)

Use WP_Query in wp_get_post_autosave

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.8 Priority: normal
Severity: normal Version: 2.6
Component: Revisions Keywords: good-first-bug has-patch has-unit-tests commit
Focuses: performance Cc:

Description

Use WP_Query in wp_get_post_autosave and replace the raw database query.

WP_Query is cached and has a number of useful filters.

Change History (25)

This ticket was mentioned in PR #7962 on WordPress/wordpress-develop by @narenin.


6 months ago
#1

  • Keywords has-patch added

This ticket was mentioned in PR #7965 on WordPress/wordpress-develop by @im3dabasia1.


6 months ago
#2

Trac ticket: https://core.trac.wordpress.org/ticket/62658

Refactored the function to use WP_Query instead of raw SQL query.

@swissspidy commented on PR #7965:


6 months ago
#3

Thanks for your PR! Looks like #7962 was a bit quicker, so let's consolidate the two.

@swissspidy commented on PR #7962:


6 months ago
#4

Additional props to @im3dabasia who opened #7965

#5 @swissspidy
6 months ago

  • Keywords needs-unit-tests added

This ticket was mentioned in PR #7969 on WordPress/wordpress-develop by @im3dabasia1.


6 months ago
#6

  • Keywords has-unit-tests added; needs-unit-tests removed

Trac ticket: https://core.trac.wordpress.org/ticket/62658

This PR adds unit tests for the wp_get_post_autosave() function. The tests cover:

  1. Checking if a post has no autosave.
  2. Verifying that an autosave is created after a revision.
  3. Ensuring autosaves are added for a specific user.

@im3dabasia1 commented on PR #7969:


6 months ago
#7

Hey @swissspidy,

I’ve added some unit tests. This is my first time contributing to unit tests, and I included the previous diff in my PR as I wasn’t sure of the best way to write tests for the new diff.

Please, whenever you have a moment, could you check this and provide feedback?

@swissspidy commented on PR #7969:


6 months ago
#8

No need to create a new PR for the tests, you can add them to the existing one.

@im3dabasia1 commented on PR #7969:


6 months ago
#9

No need to create a new PR for the tests, you can add them to the existing one.

Thanks for your suggestion! I’m not entirely sure how I can push changes directly into someone else’s PR. I’m also unsure if I have write access to the branch for this PR, so I’m uncertain about the process for doing that.

When I reviewed other tickets that required unit tests in the past, I saw that a separate patch or PR was raised for those. I followed that approach here, assuming it was the preferred method.

Could you kindly guide me on how to proceed with adding the unit tests to the existing PR? I’d appreciate your help!

@narenin commented on PR #7969:


6 months ago
#10

@im3dabasia I have added the Test case in #7962

#12 @mukesh27
6 months ago

  • Milestone changed from Future Release to 6.8

Move to 6.8 for visibility

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


6 months ago

#14 @flixos90
5 months ago

From what I can tell, the PR https://github.com/WordPress/wordpress-develop/pull/7962 could use a follow up review. @spacedmonkey Any chance you can take another look? I'm asking since you requested changes previously.

#15 @spacedmonkey
5 months ago

I have submitted a review.

@mukesh27 commented on PR #7962:


5 months ago
#16

@narenin take a look pending feedback https://github.com/WordPress/wordpress-develop/pull/7962#discussion_r1875403456 from @spacedmonkey

@narenin commented on PR #7962:


5 months ago
#17

@spacedmonkey I have implemented suggestions, could you please take a look.

#18 @spacedmonkey
5 months ago

  • Owner set to spacedmonkey
  • Status changed from new to assigned

@im3dabasia1 commented on PR #7962:


5 months ago
#19

Hi @spacedmonkey,

Would we be eligible to receive the Testing badge once this PR is merged? I initially contributed to the tests in the PR, which was later merged into this PR. I was wondering if I might still be eligible for the badge.

Nice work @narenin 💯

@narenin commented on PR #7962:


5 months ago
#20

@spacedmonkey thanks for the feedbacks, I have implemented the suggestions could you please take the look.

@swissspidy commented on PR #7962:


5 months ago
#21

@im3dabasia See https://make.wordpress.org/test/handbook/test-team-profile-badges/ for that badge and its requirements and how to request it if you meet them.

@spacedmonkey LGTM

#22 @mukesh27
5 months ago

  • Keywords commit added

Mark for commit consideration.

This ticket was mentioned in PR #8198 on WordPress/wordpress-develop by @spacedmonkey.


5 months ago
#23

Trac ticket:

#24 @spacedmonkey
5 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 59715:

Revisions: Use WP_Query in wp_get_post_autosave.

Replaced the raw SQL query in the wp_get_post_autosave function with a WP_Query call. This change improves code maintainability and replaces the raw SQL query with a cacheable query via WP_Query.

Props narenin, swissspidy, mukesh27, spacedmonkey, im3dabasia1.
Fixes #62658.

Note: See TracTickets for help on using tickets.