Index: acp_main.php =================================================================== --- acp_main.php (revision 1527) +++ acp_main.php (working copy) @@ -186,11 +186,24 @@ // Resync post counts $start = 0; + $max_post_id = 0; + + // Find the maximum post ID, we can only stop the cycle when we've reached it + $result = $db->sql_query('SELECT MAX(forum_last_post_id) as max_post_id FROM ' . FORUMS_TABLE); + if ($row = $db->sql_fetchrow($result)) + { + $max_post_id = $row['max_post_id']; + } + else + { + add_log('critical', 'LOG_NO_MAX_POST'); // TODO: Add variable to lang file. + } + $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000; $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0'); - do + while ($start < $max_post_id) { $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id FROM ' . POSTS_TABLE . ' @@ -210,13 +223,8 @@ $start += $step; } - else - { - $start = 0; - } $db->sql_freeresult($result); } - while ($start); add_log('admin', 'LOG_RESYNC_POSTCOUNTS');