';
_e('Compare the memory limits to the memory stats shown in your cache status', 'amr-users');
echo ' '.__('go', 'amr-users').'';
echo '
';
echo '
';
_e('If the user and user meta numbers are large, you may experience problems with large lists.', 'amr-users');
echo '
';
_e('If this happens, try: increasing php memory, clean up users (get rid of the spammy users), clean up usermeta. You may have records from inactive plugins.', 'amr-users');
echo '
';
$wpdb->show_errors();
if (is_multisite() and is_network_admin()) {
$where = '';
$wheremeta = '';
_e('This is a multi-site network. All users shown here.', 'amr-users');
echo ' ';
}
else { $where = ' INNER JOIN ' . $wpdb->usermeta .
' am_um ON ' . $wpdb->users . '.ID = am_um.user_id
WHERE am_um.meta_key =\'' . $wpdb->prefix . 'capabilities\'' ;
printf(__('This website with blog_id=%s and prefix=%s has:', 'amr-users'),$GLOBALS['blog_id'],$wpdb->prefix );
$wheremeta = '';
}
echo '
';
//------------------------------------------
if (!empty($where)) // then we already know we are in a sub blog
$wheremeta = " WHERE ".$wpdb->usermeta.".user_id IN ".
"(SELECT distinct user_id FROM ".$wpdb->usermeta." WHERE ".$wpdb->usermeta .".meta_key ='" . $wpdb->prefix . "capabilities')";
echo '
'.__('These queries could be slow. Be patient. Wait:','amr-users').'
';
//------------------------------------------
if (isset($_REQUEST['getstats'])) {
echo '
'.__('Meta stats:','amr-users').'
';
echo '
';
echo '
';
track_progress('Before meta stats: ');
/* TOO SLOW
echo '
';
$sql = "SELECT COUNT(DISTINCT meta_key) FROM $wpdb->usermeta ".$wheremeta ; // 97 seconds on 1.1 million records
$total = $wpdb->get_var( $sql );
printf(__('%s different user meta keys.', 'amr-users'),number_format($total,0,'.',','));
track_progress('After count distinct usermeta:');
unset($results);
echo '
';
*/
echo '
';
$sql = "SELECT DISTINCT meta_key FROM $wpdb->usermeta"; // uses more mem but faster
echo ' Executing query: '.$sql.' ';
$results = $wpdb->get_results($sql, ARRAY_A);
$total = count($results);
printf('
'.__('%s different user meta keys.', 'amr-users').'
';
$sql = "SELECT count(*) FROM $wpdb->usermeta ".$wheremeta;
$text = __('%d user meta records.', 'amr-users');
echo ' Executing query: '.$sql.' ';
amr_count_sql ( $sql, $text, '
','
');
echo '
';
flush();
}
//------------------------------------------
if (isset($_REQUEST['testqueries'])) {
echo ''.__('Running some test queries:', 'amr-users').'';
$_GET['mem'] = true; // to make track progress work
track_progress('Test full user query memory impact:');
$sql = "SELECT ID, user_login, user_email, display_name FROM $wpdb->users".$where;
echo ' Executing query: '.$sql.' ';
$results = $wpdb->get_col( $sql, 0 );
echo ' Queried all from user master:'. count($results);
track_progress('After users - how was it?');
}
if (isset($_REQUEST['testquerymeta'])) {
track_progress('Test user meta query:');
$sql = 'SELECT user_id, meta_key, meta_value '.
" FROM $wpdb->usermeta ".$wheremeta
. " AND $wpdb->usermeta.meta_key "
." in ("
."'first_name', 'last_name', 'nickname', 'description' "
.") " ;
echo ' Executing query: '.$sql.' ';
$results = $wpdb->get_results( $sql, ARRAY_A );
echo ' Queried user meta master:'. count($results);
track_progress('After usermeta - how was it?');
echo ''.__('If these queries completed, the "fetch users directly" method should work, even if the "wp_query" method fails.', 'amr-users').__('See "How to fetch data" in the general settings.', 'amr-users').'';
}
if (isset($_REQUEST['testwpmetaquery'])) { // put in request line - just testing for now
track_progress('Test wp query impact with test query:');
$parameters = array (
'role' => 'subscriber',
'fields' => array('ID', 'user_login', 'user_email', 'display_name') // can only be main fields, so not that helpful
);
$all_users_query = new WP_User_Query( $parameters );
$results = $all_users_query->get_results();
var_dump($results[1]);
echo ' Queried all from user master:'. count($results);
track_progress('After users - how was it?');
}
echo '
'.__('Page complete. Please note memory and incremental runtimes.', 'amr-users').'
';
}
/* ----------------------------------------------------------------------------------- */
function amr_count_sql ($sql, $text, $before, $after) {
global $wpdb;
/* $results = $wpdb->get_col( $sql, 0 );
echo $before;
foreach ($results as $i => $total) {
printf($text,number_format($total,0,'.',','));
}
unset($results);
*/
$total = $wpdb->get_var( $sql ); // note prepare not necessary as we specified the input query - no user input
echo $before;
$text2 = ''.sprintf($text,number_format($total,0,'.',',')).'';
echo $text2;
track_progress('After '.$text2.': ');
echo $after;
flush();
}
/* ----------------------------------------------------------------------------------- */
function amr_count_blogs ($sql, $text) {
global $wpdb;
$sql = "SELECT count(*) FROM " . $wpdb->blogs;
$results = $wpdb->get_col( $sql, 0 );
foreach ($results as $i => $total) {
printf(__('%s sites', 'amr-users'),number_format($total,0,'.',','));
}
unset($results);
}
/* ----------------------------------------------------------------------------------- */
function amr_test_your_db() {
amr_mimic_meta_box('about', __('About your user database', 'amr-users'),'amr_about_users', false);
}
/* ---------------------------------------------------------------------*/
function amr_meta_test_your_db_page() { /* the main setting spage - num of lists and names of lists */
amr_meta_admin_headings ($plugin_page=''); // does the nonce check etc
amr_test_your_db();
}
/* ---------------------------------------------------------------------*/