function checksum_histogram($object_type, $buckets, $start_id = null, $end_id = null, $columns = null, $strip_non_ascii = true)
{
global $wpdb;
$wpdb->queries = array();
switch ($object_type) {
case "posts":
$object_count = $this->post_count(null, $start_id, $end_id);
$object_table = $wpdb->posts;
$id_field = 'ID';
$where_sql = Jetpack_Sync_Settings::get_blacklisted_post_types_sql();
if (empty($columns)) {
$columns = Jetpack_Sync_Defaults::$default_post_checksum_columns;
}
break;
case "post_meta":
$object_table = $wpdb->postmeta;
$where_sql = Jetpack_Sync_Settings::get_whitelisted_post_meta_sql();
$object_count = $this->meta_count($object_table, $where_sql, $start_id, $end_id);
$id_field = 'meta_id';
if (empty($columns)) {
$columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns;
}
break;
case "comments":
$object_count = $this->comment_count(null, $start_id, $end_id);
$object_table = $wpdb->comments;
$id_field = 'comment_ID';
$where_sql = Jetpack_Sync_Settings::get_comments_filter_sql();
if (empty($columns)) {
$columns = Jetpack_Sync_Defaults::$default_comment_checksum_columns;
}
break;
case "comment_meta":
$object_table = $wpdb->commentmeta;
$where_sql = Jetpack_Sync_Settings::get_whitelisted_comment_meta_sql();
$object_count = $this->meta_count($object_table, $where_sql, $start_id, $end_id);
$id_field = 'meta_id';
if (empty($columns)) {
$columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns;
}
break;
default:
return false;
}
$bucket_size = intval(ceil($object_count / $buckets));
$previous_max_id = 0;
$histogram = array();
$where = '1=1';
if ($start_id) {
$where .= " AND {$id_field} >= " . intval($start_id);
}
if ($end_id) {
$where .= " AND {$id_field} <= " . intval($end_id);
}
do {
list($first_id, $last_id) = $wpdb->get_row("SELECT MIN({$id_field}) as min_id, MAX({$id_field}) as max_id FROM ( SELECT {$id_field} FROM {$object_table} WHERE {$where} AND {$id_field} > {$previous_max_id} ORDER BY {$id_field} ASC LIMIT {$bucket_size} ) as ids", ARRAY_N);
// get the checksum value
$value = $this->table_checksum($object_table, $columns, $id_field, $where_sql, $first_id, $last_id, $strip_non_ascii);
if (is_wp_error($value)) {
return $value;
}
if ($first_id === null || $last_id === null) {
break;
} elseif ($first_id === $last_id) {
$histogram[$first_id] = $value;
} else {
$histogram["{$first_id}-{$last_id}"] = $value;
}
$previous_max_id = $last_id;
} while (true);
return $histogram;
}