WPSEO_Upgrade::deduplicate_unindexed_indexable_rows
De-duplicates indexables that have more than one "unindexed" rows for the same object. Keeps the newest indexable.
Метод класса: WPSEO_Upgrade{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->deduplicate_unindexed_indexable_rows();
Код WPSEO_Upgrade::deduplicate_unindexed_indexable_rows() WPSEO Upgrade::deduplicate unindexed indexable rows Yoast 27.6
protected function deduplicate_unindexed_indexable_rows() {
global $wpdb;
// If migrations haven't been completed successfully the following may give false errors. So suppress them.
$show_errors = $wpdb->show_errors;
$wpdb->show_errors = false;
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$duplicates = $wpdb->get_results(
$wpdb->prepare(
"
SELECT
MAX(id) as newest_id,
object_id,
object_type
FROM
%i
WHERE
post_status = 'unindexed'
AND object_type IN ( 'term', 'post', 'user' )
GROUP BY
object_id,
object_type
HAVING
count(*) > 1",
[ Model::get_table_name( 'Indexable' ) ],
),
ARRAY_A,
);
if ( empty( $duplicates ) ) {
$wpdb->show_errors = $show_errors;
return;
}
// Users, terms and posts may share the same object_id. So delete them in separate, more performant, queries.
$delete_queries = [
$this->get_indexable_deduplication_query_for_type( 'post', $duplicates, $wpdb ),
$this->get_indexable_deduplication_query_for_type( 'term', $duplicates, $wpdb ),
$this->get_indexable_deduplication_query_for_type( 'user', $duplicates, $wpdb ),
];
foreach ( $delete_queries as $delete_query ) {
if ( ! empty( $delete_query ) ) {
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
$wpdb->query( $delete_query );
// phpcs:enable
}
}
$wpdb->show_errors = $show_errors;
}