WordPress.org

Forums

[resolved] WordPress dashboard, viewing CPT results in 504 (9 posts)

  1. NWTD
    Member
    Posted 2 years ago #

    I created a custom post type with a custom taxonomy. I have about 1500 posts all of which are assigned to some sort of taxonomy term...some being assigned to 200+ terms.

    I noticed that from the dashboard, it takes an extremely long amount of time to view the custom post types, most of the time resulting in a 504 Gateway Time-Out.

    Querying these post from the front-end is just fine and I have no issues with that.

    It's my understanding that when the dashboard is trying to view these custom post types, it's trying to pull all the information assigned to each post, before it shows everything.

    I do have this WP install set to be able to use as much memory as needed (memory_limit = -1), as I was researching, some said it may be memory related.

    Is there something i can do to increase the performance of this query ...maybe not load all the taxonomy term relationships of a post until you're editing the post?

  2. phillbooth
    Member
    Posted 2 years ago #

    I suggest you try a plugin that will optimize your database.

    Have you tried to simply use the http://codex.wordpress.org/Function_Reference/edit_post_link and navigate by going through the front end.

    Get ACP running on your server and get a plugin to use this.

    https://www.google.co.uk/search?q=wp-config+pimp

    Get your wp-config.php with these settings in...

    define('WP_MEMORY_LIMIT', '64M');
    define('FS_CHMOD_DIR', (0755 & ~ umask()));
    define('FS_CHMOD_FILE', (0644 & ~ umask()));
    define('WP_POST_REVISIONS', 1);
    define('EMPTY_TRASH_DAYS', 0);
    define('WP_ALLOW_REPAIR', true);
    define('WP_CACHE', true);

    I would increase your memory limit as much as possible such as 2000M (2Gb) if you can.

    I would also check your PHP.ini file and your mysql.ini (check paging file) file if u can perhaps you should move over to a larger server?

  3. NWTD
    Member
    Posted 2 years ago #

    Thanks for the helpful suggetions phillbooth.

    I've had most of these already in place, with the exception of using 2Gb of memory...it was previously set to 1Gb.

    After increasing to 2Gb I was able to view the posts, however, I see a slew of errors:

    WordPress database error: [MySQL client ran out of memory]
    SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('locations') AND tr.object_id IN
    WordPress database error: [Lost connection to MySQL server during query]
    SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN
    WordPress database error: [MySQL server has gone away]
    SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM wp_posts WHERE post_type = 'services' ORDER BY post_date DESC

    Is there a way to alter this query so it's not so heavy? It makes it difficult to manage these posts if I have to get to them from the front-end.

    FWIW, I did repair and optimize the tables, but according to that, everything was fine and already optimized.

  4. phillbooth
    Member
    Posted 2 years ago #

    It looks like you only have a limited amount of Memory available, and the memory that MySql was using is now being taken up by you PHP processing after you increased your environmental space.

    Put your memory back to 1GB.

    You need a bigger boat... look into VPS and cloud hosting 3-4GB / SSH / WHM+Cpanel

    You need to get hosting that allows root access in SSH so you can set the global php.ini and MySql settings manually.

  5. NWTD
    Member
    Posted 2 years ago #

    Thanks phillibooth. I do have everything you suggested without the 3-4GB of memory.

    I'm trying to find some other solution rather than throwing a bunch of memory at the problem.

    I anticipate having a few other sites that will be of similar nature with the amount of posts and taxonomy terms....especially if any of these sites need to be edited simultaneously. I don't want to run into a problem where I need 50GB of memory to run a dozen websites....there's got to be a better solution.

    TIA

  6. NWTD
    Member
    Posted 2 years ago #

    Any suggestions from anyone else? -- Maybe this is posted in the wrong forum. Should this be posted under "-Hacks"? If so, can a mod move it?

  7. NWTD
    Member
    Posted 2 years ago #

    I was able to resolve this by adding this function:

    add_action( 'pre_get_posts', 'nwtd_lpfs_custom_admin_query' );
    function nwtd_lpfs_custom_admin_query( $query ) {
        if( !is_admin() && !$query->is_main_query() ) {
             return;
         }
         if( is_post_type_archive( 'services' ) ) {
              $query->set('no_found_rows', 1 );
              $query->set('update_post_meta_cache', 0 );
              $query->set('update_post_term_cache', 0 );
         }
    }
  8. luistinygod
    Member
    Posted 2 years ago #

    Hi nwtd,

    This is a very elegant solution and opens the door to heavy stuff with WordPress!

    When I proposed that code to you (inspired on WP_query codex page) I wasn't sure if it would work using this philosophy in the pre_get_posts hook. On my setup was already fast but I'm happy that it completely solved at your end!

  9. NWTD
    Member
    Posted 2 years ago #

    Thanks again luistinygod!

Topic Closed

This topic has been closed to new replies.

About this Topic