Control whether user results should be sorted when processing report filters. Disabling sorting can improve performance for very large datasets.
When fetching user data for reports, Alpha Insights can sort the results. For very large datasets, sorting can be expensive. This filter allows you to disable sorting to improve performance when order doesn't matter.
File: includes/classes/WPDAI_Report_Filters.php
Method: WPDAI_Report_Filters::get_users()
Line: ~258
| Parameter | Type | Description |
|---|---|---|
| $should_sort | bool | Whether to sort user results (default: false) |
Type: bool
Description: True to enable sorting, false to disable
add_filter( 'wpd_ai_report_filters_users_should_sort', '__return_true' );
add_filter( 'wpd_ai_report_filters_users_should_sort', 'conditional_user_sorting' );
function conditional_user_sorting( $should_sort ) {
global $wpdb;
// Get total user count
$total_users = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->users}" );
// Only sort if we have a manageable number of users
if ( $total_users < 10000 ) {
return true; // Enable sorting for smaller datasets
}
return false; // Disable sorting for large datasets
}
add_filter( 'wpd_ai_report_filters_users_should_sort', 'sort_for_specific_contexts' );
function sort_for_specific_contexts( $should_sort ) {
// Enable sorting when viewing customer reports
if ( isset( $_GET['user_type'] ) && $_GET['user_type'] === 'customer' ) {
return true;
}
return $should_sort;
}
With Sorting Enabled:
With Sorting Disabled (default):
Enable sorting if:
Keep sorting disabled if:
WPDAI_Report_Filters - Report filtering and processingadd_filter( 'wpd_ai_report_filters_users_should_sort', 'debug_user_sorting', 999 );
function debug_user_sorting( $should_sort ) {
error_log( 'Alpha Insights User Sorting: ' . ( $should_sort ? 'ENABLED' : 'DISABLED' ) );
return $should_sort;
}