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

南蛮子懋和2022年11月22日discuz5371
文章摘要
DaoGPT
此内容根据文章AI生成,并经过人工审核,仅用于文章内容的解释与总结
投诉

分析故障原因:因为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.dao.js.cn/new/20221122132.shtml

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

重构了6年前用于合规化建设的discuz插件

重构了6年前用于合规化建设的discuz插件

https://addon.dismall.com/packs/wsrc_jubao.html网络举报监督专区拓展是一个小道在六年前写的一个汇集多个官方举报平台的discuz拓展,旨在帮助用户方便快捷...

discuz添加一个是否br压缩的判断

discuz添加一个是否br压缩的判断

/template/default/common/footer.htm下将<p class="xs0"> {lang time_now} <...

评论列表

上衫绘梨衣
上衫绘梨衣   Google Chrome 86.0.4240.198  Windows 10 x64
2024年08月03日

Discuz Q 回复卡顿困扰?试试临时解决方案:清理缓存、优化数据库,提升操作体验!速效改善响应慢。

发表评论

访客

看不清,换一张

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

请如实填写常用的真实邮箱,方便后续的回复邮件通知。