当前位置:首页 > 技术 > Discuz Q > Discuz Q 回复非常卡临时解决方案

Discuz Q 回复非常卡临时解决方案

懋和道人4个月前 (11-22)Discuz Q1510

分析故障原因:因为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
        );
    }

更新缓存,故障解决

打赏

扫描二维码推送至手机访问。

版权声明:本文由 懋和道人 发布,如需转载请注明出处。

本文链接:https://www.lizhichen.cn/new/20221122132.shtml

分享给朋友:
返回列表

上一篇:Discuz Q 显示 IP 属地

没有最新的文章了...

“Discuz Q 回复非常卡临时解决方案” 的相关文章

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。