作者 邓超

x

@@ -7,6 +7,7 @@ namespace Controller\fob_ai; @@ -7,6 +7,7 @@ namespace Controller\fob_ai;
7 use Controller\Base; 7 use Controller\Base;
8 use Lib\Verify; 8 use Lib\Verify;
9 use Model\folderSql; 9 use Model\folderSql;
  10 +use function Swoole\Coroutine\Http\request;
10 11
11 /** 12 /**
12 * 黑格 fob 那边专用 业务 13 * 黑格 fob 那边专用 业务
@@ -188,7 +189,7 @@ class MailList extends Base { @@ -188,7 +189,7 @@ class MailList extends Base {
188 },$lists?:[]); 189 },$lists?:[]);
189 190
190 // 总数 191 // 总数
191 - $total = db()->count(sprintf($sql,"count(*)")); 192 + $total = db()->cache(600)->count(sprintf($sql,"count(*)"));
192 193
193 app()->_json(listsPage($lists,$total,$page,$limit)); 194 app()->_json(listsPage($lists,$total,$page,$limit));
194 195
@@ -220,42 +221,42 @@ class MailList extends Base { @@ -220,42 +221,42 @@ class MailList extends Base {
220 $where['lists|folder_id'] = $this->getFolderId('发件箱'); 221 $where['lists|folder_id'] = $this->getFolderId('发件箱');
221 // 预热发件箱 222 // 预热发件箱
222 $where['fob_hot_mail|folder'] = 'f'; 223 $where['fob_hot_mail|folder'] = 'f';
223 - $fCount = db()->count($sql.dbWhere($where)); 224 + $fCount = db()->cache(600)->count($sql.dbWhere($where));
224 } 225 }
225 226
226 // 预热收件箱 227 // 预热收件箱
227 if(in_array('hot_inbox',$show_count_filed)) { 228 if(in_array('hot_inbox',$show_count_filed)) {
228 $where['lists|folder_id'] = $this->getFolderId('收件箱'); 229 $where['lists|folder_id'] = $this->getFolderId('收件箱');
229 $where['fob_hot_mail|folder'] = 's'; 230 $where['fob_hot_mail|folder'] = 's';
230 - $sCount = db()->count($sql . dbWhere($where)); 231 + $sCount = db()->cache(600)->count($sql . dbWhere($where));
231 } 232 }
232 unset($where['fob_hot_mail|folder']); 233 unset($where['fob_hot_mail|folder']);
233 234
234 $sql = $sql." ISNULL(`lists_id`) and "; 235 $sql = $sql." ISNULL(`lists_id`) and ";
235 if(in_array('send',$show_count_filed)) { 236 if(in_array('send',$show_count_filed)) {
236 $where['lists|folder_id'] = $this->getFolderId('发件箱'); 237 $where['lists|folder_id'] = $this->getFolderId('发件箱');
237 - $faCount = db()->count($sql . dbWhere($where)); 238 + $faCount = db()->cache(600)->count($sql . dbWhere($where));
238 } 239 }
239 // 垃圾箱 240 // 垃圾箱
240 if(in_array('junk',$show_count_filed)) { 241 if(in_array('junk',$show_count_filed)) {
241 $where['lists|folder_id'] = $this->getFolderId('垃圾箱'); 242 $where['lists|folder_id'] = $this->getFolderId('垃圾箱');
242 - $lajiCount = db()->count($sql . dbWhere($where)); 243 + $lajiCount = db()->cache(600)->count($sql . dbWhere($where));
243 } 244 }
244 // 收件箱 245 // 收件箱
245 if(in_array('inbox',$show_count_filed)) { 246 if(in_array('inbox',$show_count_filed)) {
246 $where['lists|folder_id'] = $this->getFolderId('收件箱'); 247 $where['lists|folder_id'] = $this->getFolderId('收件箱');
247 - $shouCount = db()->count($sql . dbWhere($where)); 248 + $shouCount = db()->cache(600)->count($sql . dbWhere($where));
248 } 249 }
249 // 未读 250 // 未读
250 if(in_array('unseen',$show_count_filed)) { 251 if(in_array('unseen',$show_count_filed)) {
251 $where['seen'] = 0; 252 $where['seen'] = 0;
252 - $seenCount = db()->count($sql . dbWhere($where)); 253 + $seenCount = db()->cache(600)->count($sql . dbWhere($where));
253 unset($where['seen']); 254 unset($where['seen']);
254 } 255 }
255 // 星标 256 // 星标
256 if(in_array('flagged',$show_count_filed)) { 257 if(in_array('flagged',$show_count_filed)) {
257 $where['flagged'] = 1; 258 $where['flagged'] = 1;
258 - $flaggedCount = db()->count($sql . dbWhere($where)); 259 + $flaggedCount = db()->cache(600)->count($sql . dbWhere($where));
259 } 260 }
260 $data = []; 261 $data = [];
261 if(isset($shouCount)) $data['inbox'] = $shouCount; 262 if(isset($shouCount)) $data['inbox'] = $shouCount;
@@ -22,6 +22,12 @@ trait DbQuery { @@ -22,6 +22,12 @@ trait DbQuery {
22 */ 22 */
23 protected $isThrow = false; 23 protected $isThrow = false;
24 24
  25 + /**
  26 + * 是否缓存
  27 + * @var int
  28 + */
  29 + protected int $cache = 0;
  30 +
25 31
26 public function getClient() 32 public function getClient()
27 { 33 {
@@ -38,6 +44,18 @@ trait DbQuery { @@ -38,6 +44,18 @@ trait DbQuery {
38 return $this; 44 return $this;
39 } 45 }
40 46
  47 + /**
  48 + * 是否缓存结果
  49 + * @param int $ttl
  50 + * @return $this
  51 + * @author:dc
  52 + * @time 2024/8/14 14:04
  53 + */
  54 + public function cache(int $ttl){
  55 + $this->cache = $ttl;
  56 + return $this;
  57 + }
  58 +
41 59
42 /** 60 /**
43 * 查询 61 * 查询
@@ -206,9 +224,19 @@ trait DbQuery { @@ -206,9 +224,19 @@ trait DbQuery {
206 * @time 2023/2/14 16:19 224 * @time 2023/2/14 16:19
207 */ 225 */
208 public function count(string|array $sql):int{ 226 public function count(string|array $sql):int{
  227 + if($this->cache){
  228 + $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql));
  229 + if(redis()->has($key)){
  230 + return redis()->get($key,0);
  231 + }
  232 + }
209 $query = $this->query($sql); 233 $query = $this->query($sql);
210 if($query){ 234 if($query){
211 - return $query->fetch(\PDO::FETCH_COLUMN); 235 + $count = $query->fetch(\PDO::FETCH_COLUMN);
  236 + if($this->cache){
  237 + redis()->set($key,$count,$this->cache);
  238 + }
  239 + return $count;
212 } 240 }
213 return 0; 241 return 0;
214 } 242 }