正在显示
2 个修改的文件
包含
21 行增加
和
9 行删除
@@ -28,6 +28,12 @@ trait DbQuery { | @@ -28,6 +28,12 @@ trait DbQuery { | ||
28 | */ | 28 | */ |
29 | protected int $cache = 0; | 29 | protected int $cache = 0; |
30 | 30 | ||
31 | + /** | ||
32 | + * 没有数据时 也缓存 | ||
33 | + * @var bool | ||
34 | + */ | ||
35 | + protected bool $cacheNoData = true; | ||
36 | + | ||
31 | 37 | ||
32 | public function getClient() | 38 | public function getClient() |
33 | { | 39 | { |
@@ -51,8 +57,9 @@ trait DbQuery { | @@ -51,8 +57,9 @@ trait DbQuery { | ||
51 | * @author:dc | 57 | * @author:dc |
52 | * @time 2024/8/14 14:04 | 58 | * @time 2024/8/14 14:04 |
53 | */ | 59 | */ |
54 | - public function cache(int $ttl){ | 60 | + public function cache(int $ttl,bool $noData = true){ |
55 | $this->cache = $ttl; | 61 | $this->cache = $ttl; |
62 | + $this->cacheNoData = $noData; | ||
56 | return $this; | 63 | return $this; |
57 | } | 64 | } |
58 | 65 | ||
@@ -277,7 +284,13 @@ trait DbQuery { | @@ -277,7 +284,13 @@ trait DbQuery { | ||
277 | $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); | 284 | $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); |
278 | if(redis()->has($key)){ | 285 | if(redis()->has($key)){ |
279 | $this->cache = 0; | 286 | $this->cache = 0; |
280 | - return redis()->get($key,$default); | 287 | + $data = redis()->get($key,$default); |
288 | + if(!$this->cacheNoData){ | ||
289 | + if($data || $data === 0){ | ||
290 | + return $data; | ||
291 | + } | ||
292 | + } | ||
293 | + | ||
281 | } | 294 | } |
282 | } | 295 | } |
283 | $query = $this->query($sql); | 296 | $query = $this->query($sql); |
@@ -251,7 +251,7 @@ class Mail { | @@ -251,7 +251,7 @@ class Mail { | ||
251 | $blacklist = redis()->get('blacklist:'.$email_id); | 251 | $blacklist = redis()->get('blacklist:'.$email_id); |
252 | $blackFolder = ''; | 252 | $blackFolder = ''; |
253 | if($blacklist){ | 253 | if($blacklist){ |
254 | - $blackFolder = $db->value(folderSql::originFolder($email_id,'垃圾箱')); | 254 | + $blackFolder = $db->cache(86400*30)->value(folderSql::originFolder($email_id,'垃圾箱')); |
255 | } | 255 | } |
256 | 256 | ||
257 | // | 257 | // |
@@ -281,11 +281,10 @@ class Mail { | @@ -281,11 +281,10 @@ class Mail { | ||
281 | 281 | ||
282 | 282 | ||
283 | $uids = array_column($uids,'UID'); | 283 | $uids = array_column($uids,'UID'); |
284 | - $existsUids = $db->all(listsSql::getUids($email_id,$folder_id,$uids)); | ||
285 | - if($existsUids){ | ||
286 | - $existsUids = array_column($existsUids,'uid'); | ||
287 | - // 获取不存在数据库的uid | ||
288 | - $uids = array_diff($uids,$existsUids); | 284 | + foreach ($uids as $k=>$uid){ |
285 | + if($db->cache(86400*30,false)->value(listsSql::first(dbWhere(['email_id'=>$email_id,'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'))){ | ||
286 | + unset($uids[$k]); | ||
287 | + } | ||
289 | } | 288 | } |
290 | 289 | ||
291 | 290 | ||
@@ -313,7 +312,7 @@ class Mail { | @@ -313,7 +312,7 @@ class Mail { | ||
313 | $unseen = $db->count(listsSql::listCount(dbWhere([ | 312 | $unseen = $db->count(listsSql::listCount(dbWhere([ |
314 | 'seen' => 0, | 313 | 'seen' => 0, |
315 | 'deleted' => 0, | 314 | 'deleted' => 0, |
316 | - 'email_id' => $email_id, | 315 | + // 'email_id' => $email_id, |
317 | 'folder_id' => $folder_id, | 316 | 'folder_id' => $folder_id, |
318 | ]))); | 317 | ]))); |
319 | $db->update( | 318 | $db->update( |
-
请 注册 或 登录 后发表评论