无限星辰工作室-客户无限互联网动力之源

标题: Discuz!x3.4 转换到 Discuzq后 回复非常卡临时解决方案 [打印本页]

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

\app\Observer\PostObserver.php
搜索
  1. /**
  2.      * 刷新站点回复数
  3.      */
  4.     private function refreshSitePostCount()
  5.     {
  6.         $this->settings->set(
  7.             'post_count',
  8.             Post::query()
  9.                 ->where('is_approved', Post::APPROVED)
  10.                 ->whereNull('deleted_at')
  11.                 ->whereNotNull('user_id')
  12.                 ->count()
  13.         );
  14.     }
复制代码


修改为:
  1. /**
  2.      * 刷新站点回复数
  3.      */
  4.     private function refreshSitePostCount()
  5.     {
  6.         $cache = app('cache');
  7.         $cacheKey = 'post_count';
  8.         $redis_data= $cache->get($cacheKey);
  9.         if(empty($redis_data)){
  10.             $cache->put($cacheKey, Post::query()
  11.                 ->where('is_approved', Post::APPROVED)
  12.                 ->whereNull('deleted_at')
  13.                 ->whereNotNull('user_id')
  14.                 ->count(),86400);
  15.         }
  16.         $this->settings->set(
  17.             'post_count',
  18.             $redis_data
  19.         );
  20.     }
复制代码

\app\Observer\ThreadObserver.php
搜索:
  1. /**
  2.      * 刷新站点主题数
  3.      */
  4.     private function refreshSiteThreadCount()
  5.     {
  6.         $this->settings->set(
  7.             'thread_count',
  8.             Thread::query()
  9.                 ->where('is_approved', Thread::APPROVED)
  10.                 ->whereNull('deleted_at')
  11.                 ->whereNotNull('user_id')
  12.                 ->count()
  13.         );
  14.     }
复制代码

修改:

  1. /**
  2.      * 刷新站点主题数
  3.      */
  4.     private function refreshSiteThreadCount()
  5.     {
  6.         $cache = app('cache');
  7.         $cacheKey = 'thread_count';
  8.         $redis_data= $cache->get($cacheKey);
  9.         if(empty($redis_data)){
  10.             $cache->put($cacheKey, Thread::query()
  11.                 ->where('is_approved', Thread::APPROVED)
  12.                 ->whereNull('deleted_at')
  13.                 ->whereNotNull('user_id')
  14.                 ->count(),86400);
  15.         }
  16.         $this->settings->set(
  17.             'thread_count',
  18.             $redis_data
  19.         );
  20.     }
复制代码


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




欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://www.xmspace.net/) Powered by Discuz! X3.4