WC_Admin_Log_Table_List::get_total_items_count
Get the total count of log entries in the database.
The query in this method can be slow if there are a large (100k+) rows in the database table, so this uses a transient to cache the count for 10 minutes if the count is over that threshold.
Метод класса: WC_Admin_Log_Table_List{}
Хуков нет.
Возвращает
int.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_total_items_count();
Код WC_Admin_Log_Table_List::get_total_items_count() WC Admin Log Table List::get total items count WC 10.8.1
protected function get_total_items_count() {
global $wpdb;
$where = $this->get_items_query_where();
$version = \WC_Cache_Helper::get_transient_version( 'logs-db' );
$transient_key = 'wc-log-total-items-count-' . md5( $where );
$transient = get_transient( $transient_key );
if (
false !== $transient
&& isset( $transient['value'], $transient['version'] )
&& $transient['version'] === $version
) {
return $transient['value'];
}
$count_query = "
SELECT COUNT(*)
FROM {$wpdb->prefix}woocommerce_log
{$where}
";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- The where clause is prepared in a separate method.
$count = intval( $wpdb->get_var( $count_query ) );
if ( $count > self::ITEM_COUNT_CACHE_THRESHOLD ) {
$transient = array(
'value' => $count,
'version' => \WC_Cache_Helper::get_transient_version( 'logs-db', true ),
);
set_transient( $transient_key, $transient, 10 * MINUTE_IN_SECONDS );
} else {
delete_transient( $transient_key );
}
return $count;
}