• Jack

    (@jack1132132)


    Hello,

    I’m using the Object Cache by W3 Total Cache but the speed at which the request to retrieve the listing of the members directory is still the same with or without the cache.

    How can this be?

    thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Jack

    (@jack1132132)

    Is there anyway to speed up the database query to fetch the memebers?

    @jack1132132

    Yes, have you tried to use this option “Creating Metatable for Member Directories”?

    https://docs.ultimatemember.com/article/1541-meta-table-for-member-directories

    Have you UM User caching enabled?

    https://docs.ultimatemember.com/article/45-misc-tab

    The Member Directory page is built with the use of Ajax JavaScript calls
    and can’t be cached as a HTML page by a WP caching plugin.

    Thread Starter Jack

    (@jack1132132)

    Hello,

    I have those options enabled however it still takes ~4 seconds to load a directory. The directory only lists users with a specific user role, however all users regardless of the role are added to the table um_metadata, which might be why the query is so slow.

    Is the um_metadata table strictly used for the directory listing? If so, I’ll try to add some hook actions to prevent client registrations from being added to the table. That way only professional registrations are added and the table gets smaller.


    Thank you.

    Thread Starter Jack

    (@jack1132132)

    Hello,

    Through the use of hooks I’ve removed the chance for my clients to be added to the wp_um_metadata table since clients aren’t listed anywhere.

    function avoid_clients_directory_on_updated_usermeta($meta_id, $object_id, $meta_key, $_meta_value){
    ...
    	if ( $is_client ) {
    
    		remove_action( 'updated_user_meta', array( $member_directory_meta_this, 'on_update_usermeta' ), 10 );
    	}
    }
    
    
     
    
    function avoid_clients_directory_on_added_usermeta($meta_id, $object_id, $meta_key, $_meta_value){
    
    ...
    	if ( $is_client ) 
    
    		remove_action( 'added_user_meta', array( $member_directory_meta_this, 'on_update_usermeta' ), 10 );
    
    
    ...
    
    }
    
    function avoid_client_members_for_directory() {
    
    	add_action( 'updated_user_meta', 'avoid_clients_directory_on_updated_usermeta' , 9, 4 );
    	add_action( 'added_user_meta', 'avoid_clients_directory_on_added_usermeta' , 9, 4 );
    }
    add_action( 'plugins_loaded', 'avoid_client_members_for_directory' );
    

    And I’ve manual deleted client records from the table too which made it much smaller.
    I think it made a small difference, however the query to list selects from the table wp_users which contains all users including clients which might be slowing down the query.


    Thank you.

    • This reply was modified 11 months, 2 weeks ago by Jack.
    Thread Starter Jack

    (@jack1132132)

    The Member Directory page is built with the use of Ajax JavaScript calls
    and can’t be cached as a HTML page by a WP caching plugin.

    The caching plug-in I’m using (W3 Total Cache) has a Database query cache, and most cache plug-ins also have the Object cache.
    Perhaps que query results could be cached using an object cache.

    I think it would make sense because many of the queries are the same so some sort of caching would improve performance and reduce load on the server.

    Thank you.

    Thread Starter Jack

    (@jack1132132)

    Something like this:

    <?php
    // Define a function to retrieve data from the database
    function get_data_from_database($query) {
        // Perform your database query here
        // ...
    
        // For the sake of this example, let's assume we fetched some data from the database
        $data = /* result of your database query */;
    
        return $data;
    }
    
    // Define a function to retrieve cached data or fetch it from the database
    function get_data($query) {
        // Generate a unique cache key based on the query parameters
        $cache_key = 'data_query_' . md5(serialize($query));
    
        // Try to retrieve the data from the cache
        $cached_data = wp_cache_get($cache_key, 'my_cache_group');
    
        // If the data is found in the cache, return it
        if ($cached_data !== false) {
            return $cached_data;
        }
    
        // If the data is not in the cache, fetch it from the database
        $data = get_data_from_database($query);
    
        // Store the data in the cache
        wp_cache_set($cache_key, $data, 'my_cache_group', 3600);
    
        return $data;
    }
    
    // Example usage
    $query1 = array('param1' => 'value1', 'param2' => 'value2');
    $result1 = get_data($query1); // Fetches data from the database and caches it
    
    $result2 = get_data($query1); // Retrieves data from the cache, avoiding the database query
    
    $query2 = array('param1' => 'value1', 'param2' => 'value3');
    $result3 = get_data($query2); // Fetches data from the database because the query parameters are different
    ?>
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Object Cache for members listing’ is closed to new replies.