WPCA has slowed down considerably

Accueil Forums Main plugin support WPCA has slowed down considerably

Mots-clés : 

5 sujets de 21 à 25 (sur un total de 25)
  • Auteur
    Messages
  • #701836
    paul_oneill
    Participant

    Executing this in PHP M yAdmin:

    select * from wp_posts where post_type = 'cuar_smart_group' AND post_title = 'CGC' AND post_status = 'publish' AND post_author = 1
    

    yields 267 rows for this one client – there are many, many more clients

    Thanks guys – I think we’re making HUGE progress now 🙂

    #703362
    Vincent Mimoun-Prat
    Admin bbPress

    By my reckoning we have 5282 cuar_criteria_search values in the wp_postmeta table – presumably there is one of these for each Smart Group entry.

    This seems to be a reasonable assumption.
    Which leads to the questions :

    – why so many groups? I guess that this may be the reason why the queries are slow. Are there duplicate groups ? How many clients do you really have?

    – is there a way to bypass smartgroups (e.g. if each of the smart groups may only retrieve 1 user each time) ?

    is there an easy way to reassign files to smart groups within the existing plugins capability, or will I need to write some funky code?

    Sorry, funky code will be the way 🙂

    One way to optimize all that would be to make use of query cache. However that would be something quite specific to your use case in order to invalidate that cache when needed (on new user, on user client ID updated, etc.)

    #703363
    Vincent Mimoun-Prat
    Admin bbPress

    Sorry, funky code will be the way

    To help you with that.

    You can use the post owner add-on (this is a core addon, you find it in the main plugin and get a reference to it using cuar_addon('post-owner')).

    It has all the functions to get and set the owners.

    If you have many duplicate groups, your algorithm would look like that maybe:

    
    1. create a dictionnary which has in key the group ID and value an array of duplicate groups
    2. for each private post (you can make a WP_Query where post_type IN (cuar_private_file, cuar_private_page, ...)
       2.a. get the owners using the post-owner addon functions as an array 
       2.b. replace each of the 'sgrp' entries in the duplicate smart groups by the original smart group
       2.c. remove duplicates from the array and save post owner using post-owner add-on function
    
    #704726
    paul_oneill
    Participant

    Hi Vincent, Thomas,

    So here’s my plan of attack:

    1. Back up the database (obviously) and test my process on the backup
    2. Identify all the “original” smart group records: post_title (downcased) same as post_slug
    3. Create a mapping of all duplicated (non-original) smart group records to the original smart group
    4. Apply this mapping to all Private Files in the database
    5. Check that no files are still attached to the duplicated smart groups
    6. Delete the duplicated smart groups
    7. Enjoy a faster website (after I fix the uploader 😉

    So my question now is: can I reassign an existing file to a different group?
    Is there a specific function I should be looked for/at?

    I’m even happy to write code that loops through ALL private files and:

    1. finds the smart group
    2. looks up the original smart group: post_title (downcased) same as post_slug
    3. Applies the original smart group

    and then complete steps 5 on as per the above

    Will this approach work?

    TIA
    Paul

    #704778
    Vincent Mimoun-Prat
    Admin bbPress

    can I reassign an existing file to a different group?
    Is there a specific function I should be looked for/at?

    Something like that should update the smart groups (not tested, should give you some ideas):

    $post_id = // the private content to reassign
    
    $post_owners = cuar_addon('post-owner');
    
    // Get the current smart group IDs
    $owners = $post_owners->get_post_owners($post_id);
    $current_smart_groups = isset($owners['sgrp']) ? $owners['sgrp'] : [];
    
    // Update the smart group IDs
    $new_smart_groups = ...; // update that array according to your algorithm
    $owners['sgrp'] = $new_smart_groups;
    
    // You can do the same for other owner types than 'srgp' if you have to
    
    // Now save new post owners for that post
    $post_owners->save_post_owners($post_id, $owners);
    
    // Repeat for other private posts
    
5 sujets de 21 à 25 (sur un total de 25)
  • Vous devez être connecté pour répondre à ce sujet.