Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#36526 closed defect (bug) (fixed)

Not needed postmeta saved when restoring post revision

Reported by: pavelevap's profile pavelevap Owned by: swissspidy's profile swissspidy
Milestone: 4.6 Priority: normal
Severity: normal Version: 3.6.1
Component: Revisions Keywords: has-patch
Focuses: Cc:

Description

WordPress stores postmeta _post_restored_from when user restores some revision, but this is never used throughout core? I did not find any notice, that this postmeta is used somewhere and only database is bloated?

https://core.trac.wordpress.org/browser/tags/4.5/src/wp-includes/revision.php#L387

Attachments (1)

36526.diff (1.9 KB) - added by swissspidy 9 years ago.

Download all attachments as: .zip

Change History (9)

#1 @ocean90
9 years ago

  • Version changed from trunk to 3.6.1

Added in [23769] and [23811], see ticket:23497:124. Unused since [25194].

#2 @swissspidy
9 years ago

Was just going to post the same ticket number, but ocean90 beat me to it.

I guess we can remove it as long as no plugins rely on it? Although they shouldn't, of course.

#3 @pavelevap
9 years ago

I thought if there should be some kind of database cleaning operation?

#4 @SergeyBiryukov
9 years ago

  • Keywords needs-patch added

Plugin directory search for _post_restored_from returned only two results:

simple-history/loggers/SimplePostLogger.php

	// Array with custom field keys to ignore because changed everytime or very internal
	$arr_meta_keys_to_ignore = array(
		"_edit_lock",
		"_edit_last",
		"_post_restored_from",
		"_wp_page_template"
	);

wr-pagebuilder/core/converter/converter.php

	$post_meta = $wpdb->get_results( "SELECT * FROM {$table_prefix}postmeta WHERE post_id = {$this->post->ID};" );
	$ignore    = array( '_edit_last', '_edit_lock', '_post_restored_from' );

	foreach ( $post_meta as $meta ) {
		if ( ! in_array( $meta->meta_key, $ignore ) ) {
			$wpdb->query( "INSERT INTO {$table_prefix}postmeta (post_id, meta_key, meta_value) VALUES ({$id}, '{$meta->meta_key}', '{$meta->meta_value}');" );
		}
	}

I think we should be able to remove it in a DB upgrade routine for 4.6.

#5 @swissspidy
9 years ago

  • Milestone changed from Awaiting Review to 4.6
  • Owner set to swissspidy
  • Status changed from new to assigned

Thanks @SergeyBiryukov!

I'll work on this DB upgrade routine + the removal of the lines in question.

@swissspidy
9 years ago

#6 @swissspidy
9 years ago

  • Keywords has-patch added; needs-patch removed

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


9 years ago

#8 @swissspidy
9 years ago

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

In 37854:

Revisions: Remove unused post meta data during database upgrade.

Introduced in [23811], WordPress displayed some additional information for restored revisions for a short period of time. This was removed again in [25194], but the meta data was still being saved unnecessarily.

After 3 years and no plugins ever using this meta data, it's time to stop collecting it.

Fixes #36526.

Note: See TracTickets for help on using tickets.