<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
#2353 (bbp_update_forum_reply_count on a 1.8MM post bbPress forum takes ~6-10 seconds)
– bbPress Trac
</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!--[if IE]><script type="text/javascript">
if (/^#__msie303:/.test(window.location.hash))
window.location.replace(window.location.hash.replace(/^#__msie303:/, '#'));
</script><![endif]-->
<link rel="search" href="/search" />
<link rel="prev" href="/ticket/2352" title="Ticket #2352" />
<link rel="last" href="/ticket/3609" title="Ticket #3609" />
<link rel="help" href="/wiki/TracGuide" />
<link rel="alternate" href="/ticket/2353?format=csv" type="text/csv" class="csv" title="Comma-delimited Text" />
<link rel="alternate" href="/ticket/2353?format=tab" type="text/tab-separated-values" class="tab" title="Tab-delimited Text" />
<link rel="alternate" href="/ticket/2353?format=rss" type="application/rss+xml" class="rss" title="RSS Feed" />
<link rel="next" href="/ticket/2354" title="Ticket #2354" />
<link rel="start" href="/wiki" />
<link rel="stylesheet" href="https://s.w.org/style/trac/common/css/trac.css?v=220" />
<link rel="stylesheet" href="https://s.w.org/style/trac/common/css/ticket.css?v=220" />
<link rel="stylesheet" href="https://s.w.org/style/trac/common/css/jquery-ui/jquery-ui.css?v=220" />
<link rel="stylesheet" href="https://s.w.org/style/trac/common/css/jquery-ui-addons.css?v=220" />
<link rel="icon" href="https://bbpress.org/favicon.ico" type="image/x-icon" />
<link rel="first" href="/ticket/1" title="Ticket #1" />
<style id="trac-noscript" type="text/css">.trac-noscript { display: none !important }</style>
<link type="application/opensearchdescription+xml" rel="search" href="/search/opensearch" title="Search bbPress Trac" />
<script type="text/javascript">
var auto_preview_timeout=2.0;
var form_token="062379bfe5c4cf42f919f09c";
var jquery_ui={"ampm":true,"date_format":"mm/dd/yy","day_names":{"abbreviated":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"narrow":["Su","Mo","Tu","We","Th","Fr","Sa"],"wide":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},"default_timezone":null,"first_week_day":0,"month_names":{"abbreviated":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"wide":["January","February","March","April","May","June","July","August","September","October","November","December"]},"period_names":{"am":["AM","AM"],"pm":["PM","PM"]},"show_timezone":false,"time_format":"hh:mm:ss TT","timepicker_separator":" ","timezone_iso8601":false,"timezone_list":null};
var comments_prefs={"comments_order":"oldest","show_comments":"true","show_prop_changes":"true"};
</script>
<link rel="dns-prefetch" href="//fonts.googleapis.com" />
<link rel="dns-prefetch" href="//www.googletagmanager.com" />
<script>//<![CDATA[
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-P24PF4B');
//]]></script>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&subset=latin%2Clatin-ext&ver=3.8.1-alpha" type="text/css" media="all" />
<link type="text/css" media="screen" rel="stylesheet" href="//bbpress.org/wp-content/themes/bb-base/style.css?v=24" />
<link type="text/css" media="screen" rel="stylesheet" href="//bbpress.org/wp-content/themes/bb-base/style-bbpress.css?v=24" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="https://s.w.org/wp-includes/css/dashicons.min.css?20150710" type="text/css" />
<link rel="stylesheet" type="text/css" href="https://s.w.org/style/trac/wp-trac.css?220" />
<script src="https://s.w.org/style/trac/common/js/jquery.js?v=220"></script>
<link rel="canonical" href="https://bbpress.trac.wordpress.org/ticket/2353" />
<script src="https://s.w.org/style/trac/common/js/babel.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/trac.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/search.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/folding.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/wikitoolbar.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/resizer.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/auto_preview.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/jquery-ui.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/jquery-ui-addons.js?v=220"></script>
<script src="https://s.w.org/style/trac/common/js/jquery-ui-i18n.js?v=220"></script>
<script type="text/javascript">
jQuery("#trac-noscript").remove();
jQuery(document).ready(function($) {
$(".trac-autofocus").focus();
$(".trac-target-new").attr("target", "_blank");
if ($.ui) { /* is jquery-ui added? */
$(".trac-datepicker:not([readonly])").prop("autocomplete", "off").datepicker();
$(".trac-datetimepicker:not([readonly])").prop("autocomplete", "off").datetimepicker();
$("#main").addClass("trac-nodatetimehint");
}
$(".trac-disable").disableSubmit(".trac-disable-determinant");
setTimeout(function() { $(".trac-scroll").scrollToTop() }, 1);
$(".trac-disable-on-submit").disableOnSubmit();
});
</script>
<script src="https://s.w.org/style/trac/common/js/threaded_comments.js?v=220"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("div.description").find("h1,h2,h3,h4,h5,h6").addAnchor(_("Link to this section"));
$(".foldable").enableFolding(false, true);
/*<![CDATA[*/
$("#attachments").toggleClass("collapsed");
$("#trac-up-attachments").click(function () {
$("#attachments").removeClass("collapsed");
return true;
});
$("#modify").parent().toggleClass("collapsed");
$(".trac-topnav a").click(function() { $("#modify").parent().removeClass("collapsed"); });
function setRevertHandler() {
$("button.trac-revert").click(function() {
var div = $("div", this);
var field_name = div[0].id.substr(7);
var field_value = div.text();
var input = $("#propertyform *[name=field_" + field_name + "]");
if (input.length > 0) {
if (input.filter("input[type=radio]").length > 0) {
input.val([field_value]);
} else if (input.filter("input[type=checkbox]").length > 0) {
input.val(field_value == "1" ? [field_value] : []);
} else {
input.val(field_value);
}
} else { // Special case for CC checkbox
input = $("#propertyform input[name=cc_update]").val([]);
}
input.change();
// Remove the revert button
if ($(this).closest("tbody").children("tr").length === 1)
$(this).closest(".trac-change-panel").remove();
else
$(this).closest("tr").remove();
return false;
});
}
setRevertHandler();
var comment_focused = false;
$("#comment").focus(function() { comment_focused = true; })
.blur(function() { comment_focused = false; });
$("#propertyform").autoSubmit({preview: '1'}, function(data, reply) {
var items = $(reply);
// Update ticket box
$("#ticket").replaceWith(items.filter('#ticket'));
// Replaces content of #changelog, without recreating it
$("#changelog").empty().append(items.filter("#changelog").contents());
// Apply comments order and "Show" preferences
applyCommentsOrder(
$('#prefs input[name="trac-comments-order"]:checked').val());
// Show warning
var new_changes = $("#changelog .trac-new");
$("#trac-edit-warning").toggle(new_changes.length != 0);
if (new_changes.length != 0)
$("#changelog").parent().show().removeClass("collapsed");
// Update view time
$("#propertyform input[name='view_time']").replaceWith(items.filter("input[name='view_time']"));
// Update preview
var preview = $("#ticketchange").html(items.filter('#preview').children());
var show_preview = preview.children().length != 0;
$("#ticketchange").toggle(show_preview);
setRevertHandler();
// Execute scripts to load stylesheets
items.filter("script").appendTo("head");
}, "#ticketchange .trac-loading");
$("#trac-comment-editor").autoSubmit({preview_comment: '1'}, function(data, reply) {
var comment = $("#trac-comment-editor").next("div.comment").html(reply);
comment.toggle(comment.children().length != 0);
}, "#changelog .trac-loading");
/*]]>*/
});
</script>
</head>
<body id="wordpress-org" class="bbpress trac wporg-make make-bbpress">
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P24PF4B" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<dl id="accessibility">
<dt>Skip to:</dt>
<dd><a href="#content" title="Skip to content">Content</a></dd>
</dl>
<div id="wporg-header">
<div id="header-inner">
<button id="mobile-menu-button" aria-expanded="false"><span class="screen-reader-text">Toggle Menu</span></button>
<ul id="wporg-header-menu">
<li><a href="https://bbpress.org/about/">About</a></li>
<li><a href="https://bbpress.org/plugins/">Plugins</a></li>
<li><a href="https://bbpress.org/themes/">Themes</a></li>
<li><a href="https://codex.bbpress.org/">Documentation</a></li>
<li><a href="https://bbpress.org/blog/">Blog</a></li>
<li><a href="https://bbpress.org/forums/">Support</a></li>
<li class="download"><a href="https://bbpress.org/download/">Download</a></li>
</ul>
<h1><a href="https://bbpress.org">bbPress.org</a></h1>
</div>
</div>
<div id="subnav">
<div id="subnav-inner">
<ul id="nav-user" class="menu">
<li class="last first">
<a href="https://login.wordpress.org/?redirect_to=https%3A%2F%2Fbbpress.trac.wordpress.org%2Fticket%2F2353" class="login">Login</a>
</li>
</ul>
</div>
</div>
<div id="banner">
<form id="search" action="/search" method="get">
<div>
<label for="proj-search">Search:</label>
<input type="text" id="proj-search" name="q" size="18" value="" />
<input type="submit" value="Search" />
</div>
</form>
</div>
<div id="mainnav" class="nav">
<ul>
<li class="first"><a href="/timeline">Timeline</a></li><li class="active"><a href="/report">View Tickets</a></li><li><a href="/roadmap">Roadmap</a></li><li><a href="/browser">Browse Source</a></li><li class="last"><a href="/ticketgraph">Ticket Graph</a></li>
</ul>
</div>
<div id="main">
<div id="ctxtnav" class="nav">
<h2>Context Navigation</h2>
<ul>
<li class="first"><span>← <a class="prev" href="/ticket/2352" title="Ticket #2352">Previous Ticket</a></span></li><li class="last"><span><a class="next" href="/ticket/2354" title="Ticket #2354">Next Ticket</a> →</span></li>
</ul>
<hr />
</div>
<div id="content" class="ticket">
<div id="ticket" class="trac-content ">
<div class="date">
<p>Opened <a class="timeline" href="/timeline?from=2013-06-15T19%3A12%3A28Z&precision=second" title="See timeline at 06/15/2013 07:12:28 PM">11 years ago</a></p>
<p>Closed <a class="timeline" href="/timeline?from=2014-02-13T05%3A06%3A32Z&precision=second" title="See timeline at 02/13/2014 05:06:32 AM">11 years ago</a></p>
<p>Last modified <a class="timeline" href="/timeline?from=2019-06-10T12%3A12%3A02Z&precision=second" title="See timeline at 06/10/2019 12:12:02 PM">5 years ago</a></p>
</div>
<h2>
<a href="/ticket/2353" class="trac-id">#2353</a>
<span class="trac-status">
<a href="/query?status=closed">closed</a>
</span>
<span class="trac-type">
<a href="/query?status=!closed&type=defect+(bug)">defect (bug)</a>
</span>
<span class="trac-resolution">
(<a href="/query?status=closed&resolution=duplicate">duplicate</a>)
</span>
</h2>
<h1 id="trac-ticket-title" class="searchable">
<span class="summary">bbp_update_forum_reply_count on a 1.8MM post bbPress forum takes ~6-10 seconds</span>
</h1>
<table class="properties">
<tr>
<th id="h_reporter">Reported by:</th>
<td headers="h_reporter" class="searchable">
<a href="https://profiles.wordpress.org/vibol" data-nicename="vibol">
<img class="avatar" src="https://wordpress.org/grav-redirect.php?user=vibol&s=48" srcset="https://wordpress.org/grav-redirect.php?user=vibol&s=96 2x" height="48" width="48" alt="vibol's profile" />
</a>
<a class="trac-author" href="/query?status=!closed&reporter=vibol">vibol</a>
</td>
<th id="h_owner">Owned by:</th>
<td headers="h_owner">
<a href="https://profiles.wordpress.org/johnjamesjacoby">
<img class="avatar" src="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=48" srcset="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=96 2x" height="48" width="48" alt="johnjamesjacoby's profile" />
</a>
<a class="trac-author" href="/query?status=!closed&owner=johnjamesjacoby">johnjamesjacoby</a>
</td>
</tr>
<tr>
<th id="h_milestone" class="missing">
Milestone:
</th>
<td headers="h_milestone">
</td>
<th id="h_priority">
Priority:
</th>
<td headers="h_priority">
<a href="/query?status=!closed&priority=normal">normal</a>
</td>
</tr><tr>
<th id="h_severity">
Severity:
</th>
<td headers="h_severity">
<a href="/query?status=!closed&severity=normal">normal</a>
</td>
<th id="h_version">
Version:
</th>
<td headers="h_version">
<a href="/query?status=!closed&version=2.2.3">2.2.3</a>
</td>
</tr><tr>
<th id="h_component">
Component:
</th>
<td headers="h_component">
<a href="/query?status=!closed&component=General+-+Performance">General - Performance</a>
</td>
<th id="h_keywords">
Keywords:
</th>
<td headers="h_keywords" class="searchable">
<a href="/query?status=!closed&keywords=~needs-patch">needs-patch</a>
</td>
</tr><tr>
<th id="h_cc">
Cc:
</th>
<td headers="h_cc" class="searchable">
<a href="/query?status=!closed&cc=~UmeshSingla">UmeshSingla</a>
</td>
<th class="missing">
</th>
<td>
</td>
</tr>
</table>
<div class="description">
<h3 id="comment:description">
Description
</h3>
<div class="searchable">
<p>
This can likely use some optimization.<br />
</p>
<p>
I haven't dug in enough to come up with a solution but I believe this function is what causes the massive query attached. Perhaps these aggregates should be placed in a separate table and incremented or decremented according to the posts added/removed. At the numbers I'm working with, eventual consistency of the aggregate numbers is acceptable.<br />
</p>
<p>
Scenarios affected: Add new post, Reply to post, Trash post, Delete post.<br />
</p>
<p>
Action execution times: ~6-10s depending on freshness of data in memory and size of forum.<br />
</p>
<p>
System: 12-core, 64GB RAM<br />
</p>
<p>
Function in question: bbp_update_forum_reply_count <br />
</p>
<p>
Actual query: see attached.<br />
</p>
</div>
</div>
</div>
<div id="attachments">
<h3 class="foldable">Attachments <span class="trac-count">(1)</span></h3>
<div class="attachments">
<dl class="attachments">
<dt>
<a href="/attachment/ticket/2353/bbp_update_forum_reply_count_query_log.txt" title="View attachment">bbp_update_forum_reply_count_query_log.txt</a><a href="/raw-attachment/ticket/2353/bbp_update_forum_reply_count_query_log.txt" class="trac-rawlink" title="Download"></a> (<span title="423495 bytes">413.6 KB</span>) - added by <span class="trac-author">vibol</span> <a class="timeline" href="/timeline?from=2013-06-15T19%3A12%3A37Z&precision=second" title="See timeline at 06/15/2013 07:12:37 PM">11 years ago</a>.
</dt>
</dl>
<p>
Download all attachments as: <a rel="nofollow" href="/zip-attachment/ticket/2353/">.zip</a>
</p>
</div>
</div>
<div>
<div class="trac-noscript" style="position: relative">
<form id="prefs" method="get" action="/prefs" style="position: absolute; right: 0">
<div id="trac-comments-order">
<input type="radio" id="trac-comments-oldest" name="trac-comments-order" value="oldest" checked="checked" />
<label for="trac-comments-oldest">Oldest first</label>
<input type="radio" id="trac-comments-newest" name="trac-comments-order" value="newest" />
<label for="trac-comments-newest">Newest first</label>
<span id="trac-threaded-toggle" style="display: none">
<input type="radio" id="trac-comments-threaded" name="trac-comments-order" value="threaded" />
<label for="trac-comments-threaded">Threaded</label>
</span>
</div>
<div>
<input id="trac-show-comments-toggle" type="checkbox" checked="checked" />
<label for="trac-show-comments-toggle">Show comments</label>
<input id="trac-show-property-changes-toggle" type="checkbox" />
<label for="trac-show-property-changes-toggle">Show property changes</label>
</div>
</form>
</div>
<h3 class="foldable">Change History <span class="trac-count">(12)</span></h3>
<div id="changelog">
<div class="change">
<h3 class="change">
<span class="threading">
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/vibol" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=vibol&s=48" srcset="https://wordpress.org/grav-redirect.php?user=vibol&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="vibol" data-nicename="vibol"><span class="trac-author">vibol</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2013-06-15T19%3A12%3A37Z&precision=second" title="See timeline at 06/15/2013 07:12:37 PM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<ul class="changes">
<li class="trac-field-attachment">
<strong class="trac-field-attachment">Attachment</strong>
<a href="/attachment/ticket/2353/bbp_update_forum_reply_count_query_log.txt"><em>bbp_update_forum_reply_count_query_log.txt</em></a><a href="/raw-attachment/ticket/2353/bbp_update_forum_reply_count_query_log.txt" title="Download" class="trac-rawlink"></a>
added
</li>
</ul>
</div>
<div class="change" id="trac-change-1-1371966781349253">
<h3 class="change">
<span class="threading">
<span id="comment:1" class="cnum">
<a href="#comment:1">#1</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/johnjamesjacoby" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=48" srcset="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="johnjamesjacoby" data-nicename="johnjamesjacoby"><span class="trac-author">johnjamesjacoby</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2013-06-23T05%3A53%3A01Z&precision=second" title="See timeline at 06/23/2013 05:53:01 AM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<ul class="changes">
<li class="trac-field-keywords">
<strong class="trac-field-keywords">Keywords</strong>
<em>needs-patch</em> added
</li><li class="trac-field-milestone">
<strong class="trac-field-milestone">Milestone</strong>
changed from <em>Awaiting Review</em> to <em>2.5</em>
</li>
</ul>
<div class="comment searchable">
<p>
Moving to 2.5 so we can address this with a few other performance issues. Thanks for attaching the log.<br />
</p>
</div>
</div>
<div class="change" id="trac-change-2-1385135318159784">
<h3 class="change">
<span class="threading">
<span id="comment:2" class="cnum">
<a href="#comment:2">#2</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/johnjamesjacoby" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=48" srcset="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="johnjamesjacoby" data-nicename="johnjamesjacoby"><span class="trac-author">johnjamesjacoby</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2013-11-22T15%3A48%3A38Z&precision=second" title="See timeline at 11/22/2013 03:48:38 PM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<ul class="changes">
<li class="trac-field-milestone">
<strong class="trac-field-milestone">Milestone</strong>
changed from <em>2.5</em> to <em>2.6</em>
</li>
</ul>
<div class="comment searchable">
<p>
Bump to 2.6.<br />
</p>
</div>
</div>
<div class="change" id="trac-change-3-1386195623804116">
<h3 class="change">
<span class="threading">
<span id="comment:3" class="cnum">
<a href="#comment:3">#3</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/johnjamesjacoby" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=48" srcset="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="johnjamesjacoby" data-nicename="johnjamesjacoby"><span class="trac-author">johnjamesjacoby</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2013-12-04T22%3A20%3A23Z&precision=second" title="See timeline at 12/04/2013 10:20:23 PM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<ul class="changes">
<li class="trac-field-component">
<strong class="trac-field-component">Component</strong>
changed from <em>General</em> to <em>Performance Improvements</em>
</li>
</ul>
</div>
<div class="change" id="trac-change-4-1386196054397910">
<h3 class="change">
<span class="threading">
<span id="comment:4" class="cnum">
<a href="#comment:4">#4</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/johnjamesjacoby" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=48" srcset="https://wordpress.org/grav-redirect.php?user=johnjamesjacoby&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="johnjamesjacoby" data-nicename="johnjamesjacoby"><span class="trac-author">johnjamesjacoby</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2013-12-04T22%3A27%3A34Z&precision=second" title="See timeline at 12/04/2013 10:27:34 PM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<ul class="changes">
<li class="trac-field-owner">
<strong class="trac-field-owner">Owner</strong>
set to <em>johnjamesjacoby</em>
</li>
</ul>
</div>
<div class="change" id="trac-change-5-1389770727878392">
<h3 class="change">
<span class="threading">
<span id="comment:5" class="cnum">
<a href="#comment:5">#5</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/netweb" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=netweb&s=48" srcset="https://wordpress.org/grav-redirect.php?user=netweb&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="netweb" data-nicename="netweb"><span class="trac-author">netweb</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2014-01-15T07%3A25%3A27Z&precision=second" title="See timeline at 01/15/2014 07:25:27 AM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<div class="comment searchable">
<p>
Some quick stats based on 1 forum with 827 Topics and 1,640 replies ( @vibol's above info is ~22,500 topics in 1 forum)<br />
</p>
<p>
<code>bbp_update_forum_reply_count</code> (<a class="ext-link" href="https://bbpress.trac.wordpress.org/browser/trunk/includes/forums/functions.php#L1519"><span class="icon"></span>\includes\forums\functions.php#1519</a>)<br />
</p>
<p>
Current: <code>Query took 0.0327 sec</code> (Each of the 827 topic id's in this forum omitted for readability)<br />
</p>
<div class="wiki-code"><div class="code"><pre><span class="k">SELECT</span> <span class="k">COUNT</span><span class="p">(</span>ID<span class="p">)</span>
<span class="k">FROM</span> wp_posts
<span class="k">WHERE</span> post_parent
<span class="k">IN</span> <span class="p">(</span> <span class="mi">103020</span><span class="p">,</span><span class="mi">103016</span><span class="p">,</span><span class="mi">103013</span><span class="p">,</span><span class="mi">103010</span><span class="p">,</span><span class="mi">103006</span><span class="p">...</span> <span class="p">)</span>
<span class="k">AND</span> post_status <span class="o">=</span> <span class="s1">'publish'</span> <span class="k">AND</span> post_type <span class="o">=</span> <span class="s1">'reply'</span><span class="p">;</span>
</pre></div></div><p>
Alternate: <code>Query took 0.0141 sec</code><br />
</p>
<div class="wiki-code"><div class="code"><pre><span class="cp"><?php</span>
<span class="nv">$reply_count</span> <span class="o">=</span> <span class="p">(</span><span class="nx">int</span><span class="p">)</span> <span class="nv">$wpdb</span><span class="o">-></span><span class="na">get_var</span><span class="p">(</span> <span class="nv">$wpdb</span><span class="o">-></span><span class="na">prepare</span><span class="p">(</span> <span class="s2">"SELECT COUNT(ID) FROM </span><span class="si">{</span><span class="nv">$wpdb</span><span class="o">-></span><span class="na">posts</span><span class="si">}</span><span class="s2"> WHERE post_parent IN ( SELECT ID FROM `wp_posts` WHERE `post_parent` = </span><span class="si">$forum_id</span><span class="s2"> ) AND post_status = '%s' AND post_type = '%s';"</span><span class="p">,</span> <span class="nx">bbp_get_public_status_id</span><span class="p">(),</span> <span class="nx">bbp_get_reply_post_type</span><span class="p">()</span> <span class="p">)</span> <span class="p">);</span>
</pre></div></div><p>
SQL<br />
</p>
<div class="wiki-code"><div class="code"><pre><span class="k">SELECT</span> <span class="k">COUNT</span><span class="p">(</span>ID<span class="p">)</span>
<span class="k">FROM</span> wp_posts
<span class="k">WHERE</span> post_parent
<span class="k">IN</span> <span class="p">(</span>
<span class="k">SELECT</span> ID <span class="k">FROM</span> <span class="o">`</span>wp_posts<span class="o">`</span> <span class="k">WHERE</span> <span class="o">`</span>post_parent<span class="o">`</span> <span class="o">=</span> <span class="mi">96480</span>
<span class="p">)</span>
<span class="k">AND</span> post_status <span class="o">=</span> <span class="s1">'publish'</span> <span class="k">AND</span> post_type <span class="o">=</span> <span class="s1">'reply'</span>
</pre></div></div><p>
This conservatively halves the query time though because we are not using <code>bbp_forum_query_topic_ids</code> we are including 'any' reply including those that are NOT public.<br />
</p>
<p>
Pretty much just thinking out loud here...<br />
</p>
</div>
</div>
<div class="change" id="trac-change-6-1391496804698945">
<h3 class="change">
<span class="threading">
<span id="comment:6" class="cnum">
<a href="#comment:6">#6</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/netweb" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=netweb&s=48" srcset="https://wordpress.org/grav-redirect.php?user=netweb&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="netweb" data-nicename="netweb"><span class="trac-author">netweb</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2014-02-04T06%3A53%3A24Z&precision=second" title="See timeline at 02/04/2014 06:53:24 AM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<div class="comment searchable">
<p>
Related: <a class="new ticket" href="/ticket/2533" title="#2533: enhancement: Optimize Repair Tools SQL Queries (new)">#2533</a><br />
</p>
</div>
</div>
<div class="change" id="trac-change-7-1391497085238484">
<h3 class="change">
<span class="threading">
<span id="comment:7" class="cnum">
<a href="#comment:7">#7</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/netweb" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=netweb&s=48" srcset="https://wordpress.org/grav-redirect.php?user=netweb&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="netweb" data-nicename="netweb"><span class="trac-author">netweb</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2014-02-04T06%3A58%3A05Z&precision=second" title="See timeline at 02/04/2014 06:58:05 AM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<div class="comment searchable">
<p>
Extending this ticket to include 'all the forum things' around <code>bbp_update_forum()</code><br />
</p>
<ul><li><code>bbp_update_forum_last_topic_id</code>
</li><li><code>bbp_update_forum_last_reply_id</code>
</li><li><code>bbp_update_forum_last_active_id</code>
</li><li><code>bbp_update_forum_last_active_time</code>
</li><li><code>bbp_update_forum_subforum_count</code>
</li><li><code>bbp_update_forum_reply_count</code>
</li><li><code>bbp_update_forum_topic_count</code>
</li><li><code>bbp_update_forum_topic_count_hidden</code>
</li></ul>
</div>
</div>
<div class="change" id="trac-change-8-1392246302675583">
<h3 class="change chat-bot">
<span class="avatar">
<span class="username-line">
<img src="https://wordpress.org/grav-redirect.php?user=ircbot&s=48" srcset="https://wordpress.org/grav-redirect.php?user=ircbot&s=96 2x" height="48" width="48" alt="" />
<p>
<em>This ticket was mentioned in IRC in #bbpress-dev by netweb. <a class="ext-link" href="http://irclogs.wordpress.org/chanlog.php?channel=bbpress-dev&day=2014-02-12&sort=asc#m15220"><span class="icon"></span>View the logs</a>.</em><br />
</p>
</span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2014-02-12T23%3A05%3A02Z&precision=second" title="See timeline at 02/12/2014 11:05:02 PM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
</div>
<div class="change" id="trac-change-9-1392267992192866">
<h3 class="change">
<span class="threading">
<span id="comment:9" class="cnum">
<a href="#comment:9">#9</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/netweb" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=netweb&s=48" srcset="https://wordpress.org/grav-redirect.php?user=netweb&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="netweb" data-nicename="netweb"><span class="trac-author">netweb</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2014-02-13T05%3A06%3A32Z&precision=second" title="See timeline at 02/13/2014 05:06:32 AM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<ul class="changes">
<li class="trac-field-milestone">
<strong class="trac-field-milestone">Milestone</strong>
<em>2.6</em> deleted
</li><li class="trac-field-resolution">
<strong class="trac-field-resolution">Resolution</strong>
set to <em>duplicate</em>
</li><li class="trac-field-status">
<strong class="trac-field-status">Status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
</ul>
<div class="comment searchable">
<p>
Closing this ticket in favor of <a class="closed ticket" href="/ticket/1799" title="#1799: defect (bug): Introduce 'bump' functions to replace costly recounts (closed: fixed)">#1799</a> as it already has a work in progress patch for <code>bbp_update_forum_reply_count</code><br />
</p>
</div>
</div>
<div class="change" id="trac-change-10-1392280862375287">
<h3 class="change chat-bot">
<span class="avatar">
<span class="username-line">
<img src="https://wordpress.org/grav-redirect.php?user=ircbot&s=48" srcset="https://wordpress.org/grav-redirect.php?user=ircbot&s=96 2x" height="48" width="48" alt="" />
<p>
<em>This ticket was mentioned in IRC in #bbpress-dev by sc0ttkclark. <a class="ext-link" href="http://irclogs.wordpress.org/chanlog.php?channel=bbpress-dev&day=2014-02-13&sort=asc#m15319"><span class="icon"></span>View the logs</a>.</em><br />
</p>
</span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2014-02-13T08%3A41%3A02Z&precision=second" title="See timeline at 02/13/2014 08:41:02 AM">11 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
</div>
<div class="change" id="trac-change-11-1560168722034125">
<h3 class="change">
<span class="threading">
<span id="comment:11" class="cnum">
<a href="#comment:11">#11</a>
</span>
</span>
<span class="avatar">
<span class="username-line"><a href="https://profiles.wordpress.org/umeshsingla" class="profile-link">
<img src="https://wordpress.org/grav-redirect.php?user=umeshsingla&s=48" srcset="https://wordpress.org/grav-redirect.php?user=umeshsingla&s=96 2x" height="48" width="48" alt="" /> @<span class="username" data-username="UmeshSingla" data-nicename="umeshsingla"><span class="trac-author">UmeshSingla</span></span></a></span>
<br /><span class="time-ago"><a class="timeline" href="/timeline?from=2019-06-10T12%3A12%3A02Z&precision=second" title="See timeline at 06/10/2019 12:12:02 PM">5 years</a> ago</span>
</span>
<div class="trac-ticket-buttons">
</div>
</h3>
<div class="trac-ticket-buttons"></div>
<ul class="changes">
<li class="trac-field-cc">
<strong class="trac-field-cc">Cc</strong>
<em>UmeshSingla</em> added
</li>
</ul>
</div>
</div>
</div>
<div id="help"><strong>Note:</strong> See
<a href="/wiki/TracTickets">TracTickets</a> for help on using
tickets.</div>
</div>
<script type="text/javascript">
jQuery.loadStyleSheet("/pygments/trac.css", "text/css");
</script>
<div id="altlinks">
<a class="preferences-link" href="/prefs">Trac UI Preferences</a>
<h3>Download in other formats:</h3>
<ul>
<li class="first">
<a rel="nofollow" href="/ticket/2353?format=csv" class="csv">Comma-delimited Text</a>
</li><li>
<a rel="nofollow" href="/ticket/2353?format=tab" class="tab">Tab-delimited Text</a>
</li><li class="last">
<a rel="nofollow" href="/ticket/2353?format=rss" class="rss">RSS Feed</a>
</li>
</ul>
</div>
</div>
<div id="footer">
<div class="links">
<p>
See also:
<a href="http://wordpress.org">WordPress.org</a> •
<a href="http://bbpress.org">bbPress.org</a> •
<a href="http://buddypress.org">BuddyPress.org</a> •
<a href="http://ma.tt">Matt</a> •
<a href="http://bbpress.org/feed/" title="RSS Feed for Articles">Blog RSS</a>
</p>
</div>
<div class="details">
<p>
<a href="http://twitter.com/bbpress" class="twitter">Follow bbPress on Twitter</a> •
<a href="http://bbpress.org/about/gpl/">GPL</a> •
<a href="http://bbpress.org/contact/">Contact Us</a> •
<a href="http://bbpress.org/terms/">Terms of Service</a>
</p>
</div>
</div>
<script>
var wpTracCurrentUser = "anonymous";
</script>
<script src="https://s.w.org/style/js/navigation.min.js?20190128"></script>
<script src="https://s.w.org/style/trac/jquery.caret.min.js?ver=2015-02-01"></script>
<script src="https://s.w.org/style/trac/jquery.atwho.min.js?ver=1.0.1"></script>
<script src="https://s.w.org/style/trac/wp-trac.js?220"></script>
</body>
</html>