当前位置: 首页 > 工具软件 > discuzQ > 使用案例 >

Discuz!x3.4 转换到 Discuzq后 回复非常卡临时解决方案

骆雅昶
2023-12-01

具体情况:Discuz!x3.4 源站 数据库大小有3g 单Post表有2g以上 ,转换到Discuz! Q RC v2.3.210224后出现回复帖子出现严重卡顿现象。
故障原因:因为Discuzq每次发帖或回复都会统计一次,post表过大的情况下,会卡住
解决方法:

\app\Observer\PostObserver.php
搜索

/**
     * 刷新站点回复数
     */
    private function refreshSitePostCount()
    {
        $this->settings->set(
            'post_count',
            Post::query()
                ->where('is_approved', Post::APPROVED)
                ->whereNull('deleted_at')
                ->whereNotNull('user_id')
                ->count()
        );
    }

修改为:

/**
     * 刷新站点回复数
     */
    private function refreshSitePostCount()
    {
        $cache = app('cache');
        $cacheKey = 'post_count';
        $red_cache = $cache->get($cacheKey);
        if(empty($red_cache)){
            $cache->put($cacheKey, Post::query()
                ->where('is_approved', Post::APPROVED)
                ->whereNull('deleted_at')
                ->whereNotNull('user_id')
                ->count(),86400);
        }
        $this->settings->set(
            'post_count',
            $red_cache
        );
    }

\app\Observer\ThreadObserver.php
搜索:

/**
     * 刷新站点主题数
     */
    private function refreshSiteThreadCount()
    {
        $this->settings->set(
            'thread_count',
            Thread::query()
                ->where('is_approved', Thread::APPROVED)
                ->whereNull('deleted_at')
                ->whereNotNull('user_id')
                ->count()
        );
    }

修改:

/**
     * 刷新站点主题数
     */
    private function refreshSiteThreadCount()
    {
        $cache = app('cache');
        $cacheKey = 'thread_count';
        $red_cache = $cache->get($cacheKey);
        if(empty($red_cache)){
            $cache->put($cacheKey, Thread::query()
                ->where('is_approved', Thread::APPROVED)
                ->whereNull('deleted_at')
                ->whereNotNull('user_id')
                ->count(),86400);
        }
        $this->settings->set(
            'thread_count',
            $red_cache
        );
    }

更新缓存,故障解决
这个bug官方下版本会修复

 类似资料: