Filter: wpd_ai_report_filters_users_should_sort

Control whether user results should be sorted when processing report filters. Disabling sorting can improve performance for very large datasets.

Description

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.

Location

File: includes/classes/WPDAI_Report_Filters.php

Method: WPDAI_Report_Filters::get_users()

Line: ~258

Parameters

Parameter Type Description
$should_sort bool Whether to sort user results (default: false)

Return

Type: bool

Description: True to enable sorting, false to disable

Example Usage

Enable Sorting for User Results

add_filter( 'wpd_ai_report_filters_users_should_sort', '__return_true' );

Conditional Sorting Based on Data Volume

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
}

Enable Sorting for Specific User Roles

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;
}

Best Practices

Performance Impact

With Sorting Enabled:

With Sorting Disabled (default):

Important Notes

When to Enable Sorting

Enable sorting if:

Keep sorting disabled if:

Related Filters

Related Classes

Debugging

add_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;
}