JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
/**
* The admin optimize tool.
*
* @package LiteSpeed
* @since 1.2.1
*/
namespace LiteSpeed;
defined( 'WPINC' ) || exit();
/**
* Database optimization utilities for LiteSpeed.
*/
class DB_Optm extends Root {
/**
* Whether there are more sites hidden in multisite counts.
*
* @var bool
*/
private static $_hide_more = false;
/**
* Supported cleanup types.
*
* @var string[]
*/
private static $types = [
'revision',
'orphaned_post_meta',
'auto_draft',
'trash_post',
'spam_comment',
'trash_comment',
'trackback-pingback',
'expired_transient',
'all_transients',
'optimize_tables',
];
/**
* Convert tables to InnoDB type identifier.
*/
const TYPE_CONV_TB = 'conv_innodb';
/**
* Show if there are more sites in hidden.
*
* @since 3.0
* @return bool
*/
public static function hide_more() {
return self::$_hide_more;
}
/**
* Clean/Optimize WP tables.
*
* @since 1.2.1
* @access public
* @param string $type The type to clean.
* @param bool $ignore_multisite If ignoring multisite check.
* @return int|string The rows that will be affected, or '-' on unknown.
*/
public function db_count( $type, $ignore_multisite = false ) {
if ( 'all' === $type ) {
$num = 0;
foreach ( self::$types as $v ) {
$num += (int) $this->db_count( $v );
}
return $num;
}
if ( ! $ignore_multisite ) {
if ( is_multisite() && is_network_admin() ) {
$num = 0;
$blogs = Activation::get_network_ids();
foreach ( $blogs as $k => $blog_id ) {
if ( $k > 3 ) {
self::$_hide_more = true;
break;
}
switch_to_blog( $blog_id );
$num += (int) $this->db_count( $type, true );
restore_current_blog();
}
return $num;
}
}
global $wpdb;
switch ( $type ) {
case 'revision':
$rev_max = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_MAX );
$rev_age = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_AGE );
$sql_add = '';
if ( $rev_age ) {
$sql_add = $wpdb->prepare( ' AND post_modified < DATE_SUB( NOW(), INTERVAL %d DAY ) ', $rev_age );
}
$sql = "SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_type = 'revision' $sql_add";
if ( ! $rev_max ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
return (int) $wpdb->get_var( $sql );
}
// Has count limit.
$sql = "SELECT COUNT(*) - %d FROM `$wpdb->posts` WHERE post_type = 'revision' $sql_add GROUP BY post_parent HAVING COUNT(*) > %d";
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
$res = (array) $wpdb->get_results( $wpdb->prepare( $sql, $rev_max, $rev_max ), ARRAY_N );
Utility::compatibility();
return array_sum( array_column( $res, 0 ) );
case 'orphaned_post_meta':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->postmeta` a LEFT JOIN `$wpdb->posts` b ON b.ID=a.post_id WHERE b.ID IS NULL" );
case 'auto_draft':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'auto-draft'" );
case 'trash_post':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'trash'" );
case 'spam_comment':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'spam'" );
case 'trash_comment':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'trash'" );
case 'trackback-pingback':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback'" );
case 'expired_transient':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE %s AND option_value < %d",
$wpdb->esc_like( '_transient_timeout_' ) . '%',
time()
)
);
case 'all_transients':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_' ) . '%'
)
);
case 'optimize_tables':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA = %s AND ENGINE <> 'InnoDB' AND DATA_FREE > 0",
DB_NAME
)
);
}
return '-';
}
/**
* Clean/Optimize WP tables.
*
* @since 1.2.1
* @since 3.0 changed to private
* @access private
* @param string $type Cleanup type.
* @return string Status message.
*/
private function _db_clean( $type ) {
if ( 'all' === $type ) {
foreach ( self::$types as $v ) {
$this->_db_clean( $v );
}
return __( 'Clean all successfully.', 'litespeed-cache' );
}
global $wpdb;
switch ( $type ) {
case 'revision':
$rev_max = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_MAX );
$rev_age = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_AGE );
$postmeta = "`$wpdb->postmeta`";
$posts = "`$wpdb->posts`";
$sql_postmeta_join = function ( $table ) use ( $postmeta, $posts ) {
return "
$postmeta
CROSS JOIN $table
ON $posts.ID = $postmeta.post_id
";
};
$sql_where = "WHERE $posts.post_type = 'revision'";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$sql_add = $rev_age ? $wpdb->prepare( ' AND ' . $posts . '.post_modified < DATE_SUB( NOW(), INTERVAL %d DAY )', $rev_age ) : '';
if ( ! $rev_max ) {
$sql_where = "$sql_where $sql_add";
$sql_postmeta = $sql_postmeta_join( $posts );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DELETE $postmeta FROM $sql_postmeta $sql_where" );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DELETE FROM $posts $sql_where" );
} else {
// Has count limit.
$sql = "
SELECT COUNT(*) - %d
AS del_max, post_parent
FROM $posts
WHERE post_type = 'revision'
$sql_add
GROUP BY post_parent
HAVING COUNT(*) > %d
";
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
$res = (array) $wpdb->get_results( $wpdb->prepare( $sql, $rev_max, $rev_max ) );
$sql_where = "
$sql_where
AND post_parent = %d
ORDER BY ID
LIMIT %d
";
$sql_postmeta = $sql_postmeta_join( "(SELECT ID FROM $posts $sql_where) AS $posts" );
foreach ( $res as $v ) {
$args = [ (int) $v->post_parent, (int) $v->del_max ];
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$wpdb->query( $wpdb->prepare( "DELETE $postmeta FROM $sql_postmeta", $args ) );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$wpdb->query( $wpdb->prepare( "DELETE FROM $posts $sql_where", $args ) );
}
}
return __( 'Clean post revisions successfully.', 'litespeed-cache' );
case 'orphaned_post_meta':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( "DELETE a FROM `$wpdb->postmeta` a LEFT JOIN `$wpdb->posts` b ON b.ID=a.post_id WHERE b.ID IS NULL" );
return __( 'Clean orphaned post meta successfully.', 'litespeed-cache' );
case 'auto_draft':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( "DELETE FROM `$wpdb->posts` WHERE post_status = 'auto-draft'" );
return __( 'Clean auto drafts successfully.', 'litespeed-cache' );
case 'trash_post':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( "DELETE FROM `$wpdb->posts` WHERE post_status = 'trash'" );
return __( 'Clean trashed posts and pages successfully.', 'litespeed-cache' );
case 'spam_comment':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( "DELETE FROM `$wpdb->comments` WHERE comment_approved = 'spam'" );
return __( 'Clean spam comments successfully.', 'litespeed-cache' );
case 'trash_comment':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( "DELETE FROM `$wpdb->comments` WHERE comment_approved = 'trash'" );
return __( 'Clean trashed comments successfully.', 'litespeed-cache' );
case 'trackback-pingback':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( "DELETE FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback'" );
return __( 'Clean trackbacks and pingbacks successfully.', 'litespeed-cache' );
case 'expired_transient':
$keys_to_delete = [];
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$transients = $wpdb->get_results(
$wpdb->prepare(
"SELECT option_name FROM `$wpdb->options` WHERE option_name LIKE %s AND option_value < %d",
$wpdb->esc_like( '_transient_timeout_' ) . '%',
time()
)
);
foreach ( $transients as $transient ) {
$keys_to_delete[] = $transient->option_name;
$keys_to_delete[] = str_replace( '_transient_timeout_', '_transient_', $transient->option_name );
}
if ( ! empty( $keys_to_delete ) ) {
$placeholders = implode( ',', array_fill( 0, count( $keys_to_delete ), '%s' ) );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
"DELETE FROM `$wpdb->options` WHERE option_name IN ( $placeholders )",
$keys_to_delete
)
);
}
return __( 'Clean expired transients successfully.', 'litespeed-cache' );
case 'all_transients':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query(
$wpdb->prepare(
"DELETE FROM `$wpdb->options` WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_' ) . '%'
)
);
return __( 'Clean all transients successfully.', 'litespeed-cache' );
case 'optimize_tables':
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$result = (array) $wpdb->get_results(
$wpdb->prepare(
"SELECT table_name, DATA_FREE FROM information_schema.tables WHERE TABLE_SCHEMA = %s AND ENGINE <> 'InnoDB' AND DATA_FREE > 0",
DB_NAME
)
);
if ( $result ) {
foreach ( $result as $row ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( 'OPTIMIZE TABLE ' . esc_sql( $row->table_name ) );
}
}
return __( 'Optimized all tables.', 'litespeed-cache' );
}
}
/**
* Get all MyISAM tables.
*
* @since 3.0
* @access public
* @return array
*/
public function list_myisam() {
global $wpdb;
$like = $wpdb->esc_like( $wpdb->prefix ) . '%';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return (array) $wpdb->get_results(
$wpdb->prepare(
"SELECT TABLE_NAME as table_name, ENGINE as engine
FROM information_schema.tables
WHERE TABLE_SCHEMA = %s AND ENGINE = 'myisam' AND TABLE_NAME LIKE %s",
DB_NAME,
$like
)
);
}
/**
* Convert tables to InnoDB.
*
* @since 3.0
* @access private
* @return void
*/
private function _conv_innodb() {
global $wpdb;
$tb_param = isset( $_GET['litespeed_tb'] ) ? sanitize_text_field( wp_unslash( $_GET['litespeed_tb'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! $tb_param ) {
Admin_Display::error( 'No table to convert or invalid nonce' );
return;
}
$tb = false;
$list = $this->list_myisam();
$names = wp_list_pluck( $list, 'table_name' );
if ( in_array( $tb_param, $names, true ) ) {
$tb = $tb_param;
}
if ( ! $tb ) {
Admin_Display::error( 'No existing table' );
return;
}
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange
$wpdb->query( 'ALTER TABLE ' . esc_sql( DB_NAME ) . '.' . esc_sql( $tb ) . ' ENGINE = InnoDB' );
Debug2::debug( "[DB] Converted $tb to InnoDB" );
$msg = __( 'Converted to InnoDB successfully.', 'litespeed-cache' );
Admin_Display::success( $msg );
}
/**
* Count all autoload size.
*
* @since 3.0
* @access public
* @return object Summary with size, entries, and toplist.
*/
public function autoload_summary() {
global $wpdb;
$autoload_values = function_exists( 'wp_autoload_values_to_autoload' ) ? wp_autoload_values_to_autoload() : [ 'yes', 'on', 'auto-on', 'auto' ];
$placeholders = implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) );
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$summary = $wpdb->get_row(
$wpdb->prepare(
"SELECT SUM(LENGTH(option_value)) AS autoload_size, COUNT(*) AS autload_entries
FROM `$wpdb->options`
WHERE autoload IN ($placeholders)",
$autoload_values
)
);
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$summary->autoload_toplist = $wpdb->get_results(
$wpdb->prepare(
"SELECT option_name, LENGTH(option_value) AS option_value_length, autoload
FROM `$wpdb->options`
WHERE autoload IN ($placeholders)
ORDER BY option_value_length DESC
LIMIT 20",
$autoload_values
)
);
return $summary;
}
/**
* Handle all request actions from main cls.
*
* @since 3.0
* @access public
* @return void
*/
public function handler() {
$type = Router::verify_type();
switch ($type) {
case self::TYPE_CONV_TB:
$this->_conv_innodb();
break;
default:
if ( 'all' === $type || in_array( $type, self::$types, true ) ) {
if ( is_multisite() && is_network_admin() ) {
$blogs = Activation::get_network_ids();
foreach ( $blogs as $blog_id ) {
switch_to_blog( $blog_id );
$msg = $this->_db_clean( $type );
restore_current_blog();
}
} else {
$msg = $this->_db_clean( $type );
}
Admin_Display::success( $msg );
}
break;
}
Admin::redirect();
}
/**
* Clean DB via WP-CLI.
*
* @since 7.0
* @access public
* @param string $args Cleanup type.
* @return string|false
*/
public function handler_clean_db_cli( $args ) {
if ( defined( 'WP_CLI' ) && constant('WP_CLI') ) {
return $this->_db_clean( $args );
}
return false;
}
}