Discuz Q 回复非常卡临时解决方案
分析故障原因:因为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 ); }
更新缓存,故障解决