#55857 closed enhancement (fixed)
Usage of wp_get_post_revisions in WP_REST_Posts_Controller
Reported by: | furi3r | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | has-patch has-unit-tests add-to-field-guide |
Focuses: | rest-api, performance | Cc: |
Description
I've come across this line of code:
https://github.com/WordPress/wordpress-develop/blob/6.0/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2020
We could optimize that query since wp_get_post_revisions accepts arguments, and we are going to use only the last revision, we could use LIMIT, instead of querying all of them.
Change History (22)
This ticket was mentioned in PR #2836 on WordPress/wordpress-develop by manuelRod.
2 years ago
#2
- Keywords has-patch has-unit-tests added
Trac ticket: #55857
#4
@
2 years ago
There's a few places aside from the rest api that use wp_get_post_revisions()
to do a count that could make use of this code.
#5
@
2 years ago
@peterwilsoncc I would go first for the rest API usage, since this is introducing a new core function, and the scope here will be more limited. Then we can follow up in another trac for other core occurrences (mainly revision.php)
manuelRod commented on PR #2836:
2 years ago
#6
@spacedmonkey @peterwilsoncc I've added the new round of revisions.
#7
@
2 years ago
- Owner set to spacedmonkey
- Resolution set to fixed
- Status changed from new to closed
In 53759:
spacedmonkey commented on PR #2836:
2 years ago
#8
Committed.
#9
follow-up:
↓ 10
@
2 years ago
Maybe a silly note, but this reads odd to me as wp_get_lastest_revision_id_and_total_count
instead of wp_get_latest_revision_id_and_total_count
, especially when the docs use the word latest
and not lastest
(which I'm not certain is a word...but I'm also not certain it's not 🤣)
#10
in reply to:
↑ 9
;
follow-up:
↓ 14
@
2 years ago
Replying to JustinSainton:
Maybe a silly note, but this reads odd to me as
wp_get_lastest_revision_id_and_total_count
instead ofwp_get_latest_revision_id_and_total_count
, especially when the docs use the wordlatest
and notlastest
Good point. Looking at the tests, they mention "wp_get_last_revision_id_and_total_count()", and the variable name is $last_revision
(here and in a few other places in core), so I think this was supposed to be "last".
#14
in reply to:
↑ 10
@
2 years ago
Replying to SergeyBiryukov:
Looking at the tests, they mention "wp_get_last_revision_id_and_total_count()", and the variable name is
$last_revision
(here and in a few other places in core), so I think this was supposed to be "last".
Looks like I missed this comment making an argument in favor of "latest" instead of "last". If anyone feels strongly about that, feel free to reopen, but in that case I would also suggest updating the "last revision" wording in other places.
#15
@
2 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
My feelings are just strong enough to reopen the ticket. What is the first and last revision seems a little ambiguous to me.
What got me to reopen was that Core refers to latest posts, latest comments, etc fairly consistently based on a basic search for _last_
vs _latest_
.
I create a follow up PR.
This ticket was mentioned in PR #3020 on WordPress/wordpress-develop by peterwilsoncc.
2 years ago
#16
SergeyBiryukov commented on PR #3020:
2 years ago
#17
Looks good to me 👍
I have added a commit with some more instances. Though not directly related to the new function, it aims for more consistency in core, always referring to the latest revision as "latest" instead of "last". This can be committed separately if preferred.
We do also need the revision count.