Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/wp-admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
wp_schedule_event( time(), 'daily', 'delete_expired_transients' );
}

// Schedule sync updates cleanup.
if ( ! wp_next_scheduled( 'wp_delete_old_sync_updates' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'daily', 'wp_delete_old_sync_updates' );
}

set_screen_options();

$date_format = __( 'F j, Y' );
Expand Down
8 changes: 8 additions & 0 deletions src/wp-admin/includes/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
KEY post_parent (post_parent),
KEY post_author (post_author),
KEY type_status_author (post_type,post_status,post_author)
) $charset_collate;
CREATE TABLE $wpdb->sync_updates (
id bigint(20) unsigned NOT NULL auto_increment,
room_hash char(32) NOT NULL,

Choose a reason for hiding this comment

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

I wonder if we could come up with an understandable name for a room and not hash it. Or maybe we could reference the post ID and avoid a name/hash entirely?

update_value longtext NOT NULL,
created_at datetime NOT NULL default '0000-00-00 00:00:00',

Choose a reason for hiding this comment

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

Do you think created_at will have a use case, or just a nice to have just in case kind of thing?

Copy link
Author

Choose a reason for hiding this comment

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

This is for cleanup but the code wasn't in the PR at the time of this comment. Here we go! c993c0f

PRIMARY KEY (id),
KEY room_hash (room_hash,id)
) $charset_collate;\n";

// Single site users table. The multisite flavor of the users table is handled below.
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ function upgrade_all() {
upgrade_682();
}

if ( $wp_current_db_version < 61644 ) {
if ( $wp_current_db_version < 61697 ) {
upgrade_700();
}

Expand Down
10 changes: 10 additions & 0 deletions src/wp-includes/class-wpdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class wpdb {
'term_relationships',
'termmeta',
'commentmeta',
'sync_updates',
);

/**
Expand Down Expand Up @@ -404,6 +405,15 @@ class wpdb {
*/
public $posts;

/**
* WordPress Sync Updates table.
*
* @since 7.0.0
*
* @var string
*/
public $sync_updates;

/**
* WordPress Terms table.
*
Expand Down
31 changes: 31 additions & 0 deletions src/wp-includes/collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,34 @@ function wp_collaboration_inject_setting() {
);
}
}

/**
* Deletes sync updates older than 1 day from the wp_sync_updates table.
*
* Rows left behind by abandoned collaborative editing sessions are cleaned up
* to prevent unbounded table growth.
*
* @since 7.0.0
*/
function wp_delete_old_sync_updates() {
global $wpdb;

/**
* Filters the lifetime, in seconds, of a sync update row.
*
* By default, the lifetime is 1 day. Once a row reaches that age, it will
* automatically be deleted by a cron job.
*
* @since 7.0.0
*
* @param int $expiration The expiration age of a sync update row, in seconds.
*/
$expiration = apply_filters( 'wp_sync_updates_expiration', DAY_IN_SECONDS );

$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->sync_updates} WHERE created_at < %s",
Copy link
Member

Choose a reason for hiding this comment

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

What if a post is being edited continuously for 2 days? Would this result in the row being deleted prematurely? What would happen in that case? (TBH, I'm not clear on all the specifics of how this works.)

gmdate( 'Y-m-d H:i:s', time() - $expiration )
)
);
}
Loading
Loading