Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
9161b76
REST API: Drop a stray blank line in the author scoped autosave loop.
adamsilverstein Nov 8, 2026
b6bcc55
Tests: Fix PHPStan level 10 errors in the author scoped autosave tests.
adamsilverstein Nov 8, 2026
555e123
Merge remote-tracking branch 'origin/trunk' into pr7555-feedback
adamsilverstein Nov 8, 2026
6dc3c3e
REST API: Target 7.3 for the autosaves author parameter.
adamsilverstein Nov 8, 2026
b616cf4
Editor: Preload only the current user's autosave.
adamsilverstein Nov 8, 2026
1e304e7
REST API: Query autosaves directly for every collection request.
adamsilverstein Nov 8, 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
3 changes: 2 additions & 1 deletion src/wp-admin/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ static function ( $classes ) {
array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ),
array( rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ),
array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ),
sprintf( '%s/autosaves?context=edit', $rest_path ),
// The editor requests only the current user's autosave.
sprintf( '%s/autosaves?context=edit&author=%d', $rest_path, get_current_user_id() ),
'/wp/v2/settings',
array( '/wp/v2/settings', 'OPTIONS' ),
'/wp/v2/global-styles/themes/' . $active_theme . '?context=view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,14 @@ public function get_item( $request ) {
}

/**
* Gets a collection of autosaves using wp_get_post_autosave.
* Gets a collection of autosaves for the parent post.
*
* Contains the user's autosave, for empty if it doesn't exist.
* WordPress stores at most one autosave per author, so this contains one
* entry per author who has autosaved the parent post, newest first.
*
* @since 5.0.0
* @since 7.3.0 Autosaves are queried directly rather than filtered out of
* every revision of the parent. Added 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,21 +324,49 @@ 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;
$revisions = wp_get_post_revisions( $parent_id, array( 'check_enabled' => false ) );

foreach ( $revisions as $revision ) {
if ( str_contains( $revision->post_name, "{$parent_id}-autosave" ) ) {
$data = $this->prepare_item_for_response( $revision, $request );
$response[] = $this->prepare_response_for_collection( $data );
$query_args = array(
'post_type' => 'revision',
'post_status' => 'inherit',
'post_parent' => $parent_id,
// Unlike `name`, this does not make the query singular.
'post_name__in' => array( $parent_id . '-autosave-v1' ),
'orderby' => array(
'date' => 'DESC',
'ID' => 'DESC',
),
'posts_per_page' => -1,
// Matches the isolation of the wp_get_post_revisions() lookup this replaces.
'suppress_filters' => true,
);

if ( ! empty( $request['author'] ) ) {
$query_args['author__in'] = $request['author'];
}

$autosaves = get_posts( $query_args );

// 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;
}
$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 );
}



/**
* Retrieves the autosave's schema, conforming to JSON Schema.
*
Expand Down Expand Up @@ -507,12 +538,22 @@ public function prepare_item_for_response( $item, $request ) {
* Retrieves the query params for the autosaves collection.
*
* @since 5.0.0
* @since 7.3.0 Added the `author` parameter.
*
* @return array Collection parameters.
*/
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