Skip to content

Commit 8b6c187

Browse files
committed
Don't check for timeout when deleting all transients
1 parent 686c2d3 commit 8b6c187

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/Transient_Command.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -297,44 +297,29 @@ private function delete_all() {
297297

298298
$count = $wpdb->query(
299299
$wpdb->prepare(
300-
"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
301-
WHERE a.option_name LIKE %s
302-
AND a.option_name NOT LIKE %s
303-
AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )",
304-
$wpdb->esc_like( '_transient_' ) . '%',
305-
$wpdb->esc_like( '_transient_timeout_' ) . '%'
300+
"DELETE FROM $wpdb->options WHERE option_name LIKE %s",
301+
$wpdb->esc_like( '_transient_' ) . '%'
306302
)
307303
);
308304

309305
if ( ! is_multisite() ) {
310306
// Non-Multisite stores site transients in the options table.
311307
$count += $wpdb->query(
312308
$wpdb->prepare(
313-
"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
314-
WHERE a.option_name LIKE %s
315-
AND a.option_name NOT LIKE %s
316-
AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )",
317-
$wpdb->esc_like( '_site_transient_' ) . '%',
318-
$wpdb->esc_like( '_site_transient_timeout_' ) . '%'
309+
"DELETE FROM $wpdb->options WHERE option_name LIKE %s",
310+
$wpdb->esc_like( '_site_transient_' ) . '%'
319311
)
320312
);
321313
} elseif ( is_multisite() && is_main_site() && is_main_network() ) {
322314
// Multisite stores site transients in the sitemeta table.
323-
$count += $wpdb->query(
324-
$wpdb->prepare(
325-
"DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b
326-
WHERE a.meta_key LIKE %s
327-
AND a.meta_key NOT LIKE %s
328-
AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )",
329-
$wpdb->esc_like( '_site_transient_' ) . '%',
330-
$wpdb->esc_like( '_site_transient_timeout_' ) . '%'
331-
)
315+
$count += $wpdb->prepare(
316+
"DELETE FROM $wpdb->sitemeta WHERE option_name LIKE %s",
317+
$wpdb->esc_like( '_site_transient_' ) . '%'
332318
);
333319
}
334320

335-
// The above queries delete the transient and the transient timeout
336-
// thus each transient is counted twice.
337-
$count = $count / 2;
321+
// The above queries delete the transient and the transient timeout if exists
322+
// thus some transients may be counted twice.
338323

339324
if ( $count > 0 ) {
340325
$success_message = ( 1 === $count ) ? '%d transient deleted from the database.' : '%d transients deleted from the database.';

0 commit comments

Comments
 (0)