mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
better query for syncing post counts. Thanks to BartVB for this. ;)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8932 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
1e7a75db8f
commit
936f7d43f0
2 changed files with 23 additions and 26 deletions
|
@ -186,30 +186,29 @@ class acp_main
|
||||||
|
|
||||||
// Resync post counts
|
// Resync post counts
|
||||||
$start = 0;
|
$start = 0;
|
||||||
|
$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
|
||||||
|
|
||||||
|
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
$sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
|
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
|
||||||
FROM ' . USERS_TABLE . ' u
|
FROM ' . POSTS_TABLE . '
|
||||||
LEFT JOIN ' . POSTS_TABLE . ' p ON (u.user_id = p.poster_id AND p.post_postcount = 1 AND p.post_approved = 1)
|
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
|
||||||
GROUP BY u.user_id
|
AND post_postcount = 1 AND post_approved = 1
|
||||||
ORDER BY u.user_id ASC';
|
GROUP BY poster_id';
|
||||||
$result = $db->sql_query_limit($sql, 200, $start);
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
if ($row = $db->sql_fetchrow($result))
|
if ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['user_id']}";
|
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
while ($row = $db->sql_fetchrow($result));
|
while ($row = $db->sql_fetchrow($result));
|
||||||
|
|
||||||
$start = ($i < 200) ? 0 : $start + 200;
|
$start += $step;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1893,32 +1893,30 @@ function change_database_data(&$no_updates, $version)
|
||||||
/**
|
/**
|
||||||
* Do not resync post counts here. An admin may later do this from the ACP
|
* Do not resync post counts here. An admin may later do this from the ACP
|
||||||
$start = 0;
|
$start = 0;
|
||||||
|
$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
|
||||||
|
|
||||||
|
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
|
||||||
|
_sql($sql, $errored, $error_ary);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@flush();
|
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
|
||||||
|
FROM ' . POSTS_TABLE . '
|
||||||
$sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
|
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
|
||||||
FROM ' . USERS_TABLE . ' u
|
AND post_postcount = 1 AND post_approved = 1
|
||||||
LEFT JOIN ' . POSTS_TABLE . ' p ON (u.user_id = p.poster_id AND p.post_postcount = 1 AND p.post_approved = 1)
|
GROUP BY poster_id';
|
||||||
GROUP BY u.user_id
|
$result = _sql($sql, $errored, $error_ary);
|
||||||
ORDER BY u.user_id ASC';
|
|
||||||
$result = $db->sql_query_limit($sql, 200, $start);
|
|
||||||
|
|
||||||
if ($row = $db->sql_fetchrow($result))
|
if ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['user_id']}";
|
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
|
||||||
_sql($sql, $errored, $error_ary);
|
_sql($sql, $errored, $error_ary);
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
while ($row = $db->sql_fetchrow($result));
|
while ($row = $db->sql_fetchrow($result));
|
||||||
|
|
||||||
$start = ($i < 200) ? 0 : $start + 200;
|
$start += $step;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue