具体情况: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';
- $redis_data= $cache->get($cacheKey);
- if(empty($redis_data)){
- $cache->put($cacheKey, Post::query()
- ->where('is_approved', Post::APPROVED)
- ->whereNull('deleted_at')
- ->whereNotNull('user_id')
- ->count(),86400);
- }
- $this->settings->set(
- 'post_count',
- $redis_data
- );
- }
复制代码
\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';
- $redis_data= $cache->get($cacheKey);
- if(empty($redis_data)){
- $cache->put($cacheKey, Thread::query()
- ->where('is_approved', Thread::APPROVED)
- ->whereNull('deleted_at')
- ->whereNotNull('user_id')
- ->count(),86400);
- }
- $this->settings->set(
- 'thread_count',
- $redis_data
- );
- }
复制代码
更新缓存,故障解决
这个bug官方下版本会修复 |