function rethestats($cachename = '')
{
    global $DB, $db_prefix;
    if (!$cachename || $cachename == 'settings') {
        settings_recache();
    }
    if (!$cachename || $cachename == 'statistics') {
        // 更新首页显示的文章数
        $article_count = $DB->result($DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles WHERE visible = '1'"), 0);
        // 更新首页显示的评论数
        $comment_count = $DB->result($DB->query("SELECT COUNT(commentid) FROM {$db_prefix}comments c LEFT JOIN {$db_prefix}articles a ON (a.articleid=c.articleid) WHERE a.visible='1' AND c.visible='1'"), 0);
        // 更新首页显示的标签(Tags)数
        $tag_count = $DB->result($DB->query("SELECT COUNT(mid) FROM {$db_prefix}metas WHERE type='tag'"), 0);
        $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET article_count='{$article_count}', comment_count='{$comment_count}', tag_count='{$tag_count}'");
        //$DB->unbuffered_query("DELETE FROM {$db_prefix}metas WHERE type='tag' AND count=0");
        // 更新主人发表文章数
        $query = $DB->query("SELECT userid,articles FROM {$db_prefix}users WHERE groupid='1' OR groupid='2'");
        while ($user = $DB->fetch_array($query)) {
            $total = $DB->result($DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles WHERE visible = '1' AND uid='" . $user['userid'] . "'"), 0);
            if ($user['articles'] != $total) {
                $DB->unbuffered_query("UPDATE {$db_prefix}users SET articles='{$total}' WHERE userid='" . $user['userid'] . "'");
            }
        }
        statistics_recache();
    }
    if (!$cachename || $cachename == 'newarticles') {
        newarticles_recache();
    }
    if (!$cachename || $cachename == 'stick') {
        stick_recache();
    }
    if (!$cachename || $cachename == 'newcomments') {
        newcomments_recache();
    }
    if (!$cachename || $cachename == 'categories') {
        // 更新所有文章的评论数
        $query = $DB->query("SELECT mid,count FROM {$db_prefix}metas");
        while ($meta = $DB->fetch_array($query)) {
            $ctotal = get_meta_article_count($meta['mid']);
            if ($meta['count'] != $ctotal) {
                update_meta_count($meta['mid'], $ctotal);
            }
        }
        categories_recache();
    }
    if (!$cachename || $cachename == 'archives') {
        // 重建文章数据
        $query = $DB->query("SELECT articleid,comments FROM {$db_prefix}articles");
        while ($article = $DB->fetch_array($query)) {
            // 更新所有文章的评论数
            $ctotal = $DB->result($DB->query("SELECT COUNT(commentid) FROM {$db_prefix}comments WHERE articleid='" . $article['articleid'] . "' AND visible='1'"), 0);
            if ($article['comments'] != $ctotal) {
                $DB->unbuffered_query("UPDATE {$db_prefix}articles SET comments='{$ctotal}' WHERE articleid='" . $article['articleid'] . "'");
            }
        }
        archives_recache();
    }
    if (!$cachename || $cachename == 'hottags') {
        hottags_recache();
    }
    if (!$cachename || $cachename == 'links') {
        links_recache();
    }
    if (!$cachename || $cachename == 'stylevars') {
        stylevars_recache();
    }
    if (!$cachename || $cachename == 'allarticleids') {
        allarticleids_recache();
    }
}
Esempio n. 2
0
    header("Location: {$location}");
    exit;
}
// 更新所有分类的文章数
if ($action == 'dometadata') {
    $step = !$step ? 1 : $step;
    $percount = $percount <= 0 ? 100 : $percount;
    $start = ($step - 1) * $percount;
    $next = $start + $percount;
    $step++;
    $jumpurl = 'cp.php?job=tools&action=dometadata&step=' . $step . '&percount=' . $percount;
    $goon = 0;
    $query = $DB->query("SELECT mid,count FROM {$db_prefix}metas LIMIT {$start}, {$percount}");
    while ($meta = $DB->fetch_array($query)) {
        $goon = 1;
        $ctotal = get_meta_article_count($meta['mid']);
        if ($meta['count'] != $ctotal) {
            update_meta_count($meta['mid'], $ctotal);
        }
    }
    if ($goon) {
        redirect('正在更新 ' . $start . ' 到 ' . $next . ' 项', $jumpurl, '2');
    } else {
        $DB->unbuffered_query("DELETE FROM {$db_prefix}relationships WHERE mid='0'");
        categories_recache();
        $location = getlink('tools', 'rebuild', array('message' => 18));
        header("Location: {$location}");
        exit;
    }
}
// 重建文章数据