| @@ -38,24 +38,36 @@ | ||
| 38 | 38 | |
| 39 | 39 | $current_user = wp_get_current_user(); |
| 40 | 40 | $url = admin_url( 'edit.php?post_type=sld&page=qcsld_click_list' ); |
| 41 | 41 | $customPagHTML = ''; |
| 42 | - // Main Report Area | |
| 43 | - $total = $wpdb->get_var( | |
| 44 | - 'SELECT COUNT(*) FROM `' . $table_sql . '`' // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 45 | - ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 42 | + // Main Report Area — cache total count (invalidated when subscriptions change). | |
| 43 | + $total_cache_key = 'wpbot_email_sub_total'; | |
| 44 | + $total = wp_cache_get( $total_cache_key, 'wpbot' ); | |
| 45 | + if ( false === $total ) { | |
| 46 | + $total = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 47 | + 'SELECT COUNT(*) FROM `' . $table_sql . '`' // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 48 | + ); | |
| 49 | + wp_cache_set( $total_cache_key, $total, 'wpbot', 300 ); | |
| 50 | + } | |
| 46 | 51 | $items_per_page = 50; |
| 47 | 52 | |
| 48 | - $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;// phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 53 | + $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 49 | 54 | $offset = ( $page * $items_per_page ) - $items_per_page; |
| 50 | 55 | |
| 51 | - $rows = $wpdb->get_results( | |
| 52 | - $wpdb->prepare( | |
| 53 | - 'SELECT * FROM `' . $table_sql . '` ORDER BY id DESC LIMIT %d, %d', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 54 | - $offset, | |
| 55 | - $items_per_page | |
| 56 | - ) | |
| 57 | - ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 56 | + // Cache paginated rows per page number. | |
| 57 | + $rows_cache_key = 'wpbot_email_sub_rows_p' . $page; | |
| 58 | + $rows = wp_cache_get( $rows_cache_key, 'wpbot' ); | |
| 59 | + if ( false === $rows ) { | |
| 60 | + $rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 61 | + $wpdb->prepare( | |
| 62 | + 'SELECT * FROM `' . $table_sql . '` ORDER BY id DESC LIMIT %d, %d', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 63 | + $offset, | |
| 64 | + $items_per_page | |
| 65 | + ) | |
| 66 | + ); | |
| 67 | + wp_cache_set( $rows_cache_key, $rows, 'wpbot', 300 ); | |
| 68 | + } | |
| 69 | + | |
| 58 | 70 | $totalPage = ceil( $total / $items_per_page ); |
| 59 | 71 | |
| 60 | 72 | if ( $totalPage > 1 ) { |
| 61 | 73 | $customPagHTML = '<div><span class="wpbot_pagination">Page ' . esc_html( $page ) . ' of ' . esc_html( $totalPage ) . '</span>' . paginate_links( |