Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8b77257
Remove autosaves preload, reducing memory footprint
adamsilverstein Oct 11, 2024
9c3ff0e
Merge branch 'trunk' into ticket/62057
adamsilverstein Nov 30, 2024
1ab05ae
Try: add per_page support for autosaves
adamsilverstein May 6, 2025
76731ee
Merge branch 'trunk' into ticket/62057
adamsilverstein May 6, 2025
2851b9c
add test for per_page parameter
adamsilverstein May 6, 2025
8a7992c
Add a test for the per_page parameter
adamsilverstein May 8, 2025
5064081
Add tests for autosaves per_page parameter
adamsilverstein May 8, 2025
64b9a54
phpcbf
adamsilverstein May 20, 2025
beb3859
autosaves route test: add per_page to expected parameters
adamsilverstein May 20, 2025
a1c0cbe
preload a single autosave
adamsilverstein May 20, 2025
267d51d
phpcbf
adamsilverstein May 20, 2025
0fa5288
merge trunk
adamsilverstein Aug 26, 2025
e06ecb1
remove autosave preload entirely
adamsilverstein Aug 26, 2025
58511dc
Merge trunk into ticket/62057
adamsilverstein Aug 14, 2026
120edbc
REST API: Allow the autosaves collection to be scoped by author.
adamsilverstein Aug 14, 2026
cc03ae0
Merge remote-tracking branch 'origin/trunk' into ticket/62057
adamsilverstein Sep 25, 2026
6108638
Tests: Regenerate the REST API client fixtures for the autosaves auth…
adamsilverstein Sep 25, 2026
4725ee0
Merge trunk into ticket/62057
adamsilverstein Sep 30, 2026
916d1dd
Merge branch 'trunk' into ticket/62057
adamsilverstein Oct 17, 2026
d163ca5
Editor: Restore the unscoped autosaves preload path.
adamsilverstein Oct 17, 2026
fbb7534
REST API: Fetch author scoped autosaves in a single query.
adamsilverstein Oct 17, 2026
d6ba582
REST API: Require positive author IDs for autosaves.
adamsilverstein Oct 17, 2026
dc7a922
Tests: Cover invalid, repeated and template author autosave queries.
adamsilverstein Oct 17, 2026
68c48b0
Tests: Update the REST API client fixture for the author minimum.
adamsilverstein Oct 17, 2026
5f31cca
Tests: Give author scoped autosave tests explicit dates.
adamsilverstein Oct 17, 2026
84953d3
REST API: Simplify author scoped autosave lookup.
adamsilverstein Oct 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ public function get_item( $request ) {
* Contains the user's autosave, for empty if it doesn't exist.
*
* @since 5.0.0
* @since 7.2.0 Added support for the `author` parameter.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
Expand All @@ -321,8 +322,44 @@ public function get_items( $request ) {
// Return early as this handler doesn't add any response headers.
return new WP_REST_Response( array() );
}

$response = array();
$parent_id = $parent->ID;

if ( ! empty( $request['author'] ) ) {
$autosaves = get_posts(
array(
'post_type' => 'revision',
'post_status' => 'inherit',
'post_parent' => $parent_id,
'name' => $parent_id . '-autosave-v1',
'author__in' => $request['author'],
'orderby' => array(
'date' => 'DESC',
'ID' => 'DESC',
),
'posts_per_page' => -1,
Comment thread
westonruter marked this conversation as resolved.
'suppress_filters' => false,
)
);

// Each author has at most one autosave; keep only the newest if not.
$seen_authors = array();

foreach ( $autosaves as $autosave ) {
if ( in_array( $autosave->post_author, $seen_authors, true ) ) {
continue;
}

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.

Micronit: This blank line separates two bits of PHP code which are part of the same “paragraph”.

Suggested change

$seen_authors[] = $autosave->post_author;

$data = $this->prepare_item_for_response( $autosave, $request );
$response[] = $this->prepare_response_for_collection( $data );
}

return rest_ensure_response( $response );
}

$revisions = wp_get_post_revisions( $parent_id, array( 'check_enabled' => false ) );

foreach ( $revisions as $revision ) {
Expand Down Expand Up @@ -513,6 +550,15 @@ public function prepare_item_for_response( $item, $request ) {
public function get_collection_params() {
return array(
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
'author' => array(
'description' => __( 'Limit result set to autosaves assigned to specific authors.' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
'minimum' => 1,
),
'default' => array(),
),
);
}
}
Loading
Loading