Project

General

Profile

Actions

Bug #10654

closed

Trashing bbPress item can cause one zillion db queries

Added by Boone Gorges about 6 years ago. Updated almost 6 years ago.

Status:
Resolved
Priority name:
Normal
Assignee:
Category name:
Group Forums
Target version:
Start date:
2018-11-01
Due date:
% Done:

0%

Estimated time:
Deployment actions:

Description

A request to
[REQUEST_URI] => /groups/[groupname]/forum/topic/post-transcripts-indexes-here/?action=bbp_toggle_reply_trash&sub_action=trash&reply_id=69262&_wpnonce=12345
triggered many many recounts:

   [66] => Array
        (
            [0] => SELECT ID FROM wp_1_posts WHERE post_parent = 68708 AND post_status NOT IN ( 'draft', 'future' ) AND post_type = 'forum' ORDER BY ID DESC;
            [1] => 0.0012228488922119
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, bbp_forum_query_subforum_ids, bbp_get_all_child_ids
        )

    [67] => Array
        (
            [0] => SELECT   wp_1_posts.ID FROM wp_1_posts  INNER JOIN wp_1_postmeta ON ( wp_1_posts.ID = wp_1_postmeta.post_id ) WHERE 1=1  AND wp_1_posts.post_parent = 68708  AND ( 
  wp_1_postmeta.meta_key = '_bbp_last_active_time'
) AND wp_1_posts.post_type = 'topic' AND ((wp_1_posts.post_status = 'publish')) GROUP BY wp_1_posts.ID ORDER BY wp_1_postmeta.meta_value DESC LIMIT 0, 1
            [1] => 0.016929864883423
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, get_posts, WP_Query->query, WP_Query->get_posts
        )

    [68] => Array
        (
            [0] => SELECT wp_1_posts.* FROM wp_1_posts WHERE ID IN (68713)
            [1] => 0.0015189647674561
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, get_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches
        )

    [69] => Array
        (
            [0] => SELECT  t.*, tt.*, tr.object_id FROM wp_1_terms AS t  INNER JOIN wp_1_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_1_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('topic-tag') AND tr.object_id IN (68713) ORDER BY t.name ASC 
            [1] => 0.013630867004395
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, get_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_post_caches, update_object_term_cache, wp_get_object_terms, get_terms, WP_Term_Query->query, WP_Term_Query->get_terms
        )

    [70] => Array
        (
            [0] => SELECT post_id, meta_key, meta_value FROM wp_1_postmeta WHERE post_id IN (68713) ORDER BY meta_id ASC
            [1] => 0.001262903213501
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, get_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_post_caches, update_postmeta_cache, update_meta_cache
        )

    [71] => Array
        (
            [0] => SELECT * FROM wp_1_posts WHERE ID = 68708 LIMIT 1
            [1] => 0.0015530586242676
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, update_post_meta, wp_is_post_revision, wp_get_post_revision, get_post, WP_Post::get_instance
        )

    [72] => Array
        (
            [0] => SELECT post_id, meta_key, meta_value FROM wp_1_postmeta WHERE post_id IN (68708) ORDER BY meta_id ASC
            [1] => 0.0014889240264893
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, update_post_meta, update_metadata, get_metadata, update_meta_cache
        )

    [73] => Array
        (
            [0] => SELECT meta_id FROM wp_1_postmeta WHERE meta_key = '_bbp_last_topic_id' AND post_id = 68708
            [1] => 0.0012459754943848
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, update_post_meta, update_metadata
        )

    [74] => Array
        (
            [0] => UPDATE `wp_1_postmeta` SET `meta_value` = '68713' WHERE `post_id` = 68708 AND `meta_key` = '_bbp_last_topic_id'
            [1] => 0.0010261535644531
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, update_post_meta, update_metadata
        )

    [75] => Array
        (
            [0] => SELECT ID FROM wp_1_posts WHERE post_parent = 68707 AND post_status NOT IN ( 'draft', 'future' ) AND post_type = 'forum' ORDER BY ID DESC;
            [1] => 0.001187801361084
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, bbp_forum_query_subforum_ids, bbp_get_all_child_ids
        )

    [76] => Array
        (
            [0] => SELECT   wp_1_posts.ID FROM wp_1_posts  INNER JOIN wp_1_postmeta ON ( wp_1_posts.ID = wp_1_postmeta.post_id ) WHERE 1=1  AND wp_1_posts.post_parent = 68707  AND ( 
  wp_1_postmeta.meta_key = '_bbp_last_active_time'
) AND wp_1_posts.post_type = 'topic' AND ((wp_1_posts.post_status = 'publish')) GROUP BY wp_1_posts.ID ORDER BY wp_1_postmeta.meta_value DESC LIMIT 0, 1
            [1] => 0.01375412940979
            [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_template_redirect, do_action('bbp_template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_get_request, do_action('bbp_get_request'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_toggle_reply_handler, wp_trash_post, do_action('trashed_post'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_trashed_reply, do_action('bbp_trashed_reply'), WP_Hook->do_action, WP_Hook->apply_filters, bbp_update_reply_walker, bbp_update_forum_last_topic_id, bbp_update_forum_last_topic_id, get_posts, WP_Query->query, WP_Query->get_posts
        )

This roughly corresponds to a set of queries that happens for a large number of posts.

I think what's happening here has to do with the way that bbPress has a single "forum parent" for all BP-group-linked forums, so that changing one item can trigger recounts for many other unrelated ones. See #4761.

I'll examine this in more detail in the upcoming days.


Related issues

Related to CUNY Academic Commons - Bug #4761: Forum Posts, Slow to SubmitResolvedBoone Gorges2015-10-09

Actions
Actions #1

Updated by Boone Gorges about 6 years ago

  • Related to Bug #4761: Forum Posts, Slow to Submit added
Actions #2

Updated by Boone Gorges almost 6 years ago

  • Target version changed from 1.13.13 to 1.14.1
Actions #3

Updated by Boone Gorges almost 6 years ago

  • Target version changed from 1.14.1 to 1.14.2
Actions #4

Updated by Boone Gorges almost 6 years ago

  • Status changed from Assigned to Resolved
Actions

Also available in: Atom PDF