Skip to content
Closed
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
6 changes: 6 additions & 0 deletions packages/sync/src/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ public static function get_callable_whitelist() {
'slug',
);

static $default_term_relationships_checksum_columns = array(
'object_id',
'term_taxonomy_id',
'term_order',
);

static $default_multisite_callable_whitelist = array(
'network_name' => array( 'Jetpack', 'network_name' ),
'network_allow_new_registrations' => array( 'Jetpack', 'network_allow_new_registrations' ),
Expand Down
13 changes: 13 additions & 0 deletions packages/sync/src/Replicastore.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function term_count() {
return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->terms" );
}

public function term_relationship_count() {
global $wpdb;
return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_relationships" );
}

public function post_count( $status = null, $min_id = null, $max_id = null ) {
global $wpdb;

Expand Down Expand Up @@ -659,6 +664,8 @@ function get_checksum_columns_for_object_type( $object_type ) {
return Defaults::$default_post_meta_checksum_columns;
case 'terms':
return Defaults::$default_term_checksum_columns;
case 'term_relationships':
return Defaults::$default_term_relationships_checksum_columns;
default:
return false;
}
Expand Down Expand Up @@ -704,6 +711,12 @@ function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id =
$id_field = 'term_id';
$where_sql = '1=1';
break;
case 'term_relationships':
$object_table = $wpdb->term_relationships;
$object_count = $this->term_relationship_count();
$id_field = 'object_id';
Copy link
Member

Choose a reason for hiding this comment

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

The object_id column isn't really a unique ID, so we can't use it for identifying a particular row. It's as much of a ID field as the term taxonomy ID. Should we be concerned about this? Should we be able to calculate histogram for tables that lack a unique ID field?

I'm basically concerned for cases when we have 1000 term relationships for 1 post, and then 1 term relationship per post after that. It just feels like it's not a reliable way to limit terms.

What do you think? Should we use some sort of calculation of both IDs?

$where_sql = '1=1';
break;
default:
return false;
}
Expand Down