作者 张关杰

合并

@@ -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
@@ -278,7 +285,13 @@ trait DbQuery { @@ -278,7 +285,13 @@ trait DbQuery {
278 $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); 285 $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql));
279 if(redis()->has($key)){ 286 if(redis()->has($key)){
280 $this->cache = 0; 287 $this->cache = 0;
281 - return redis()->get($key,$default); 288 + $data = redis()->get($key,$default);
  289 + if(!$this->cacheNoData){
  290 + if($data || $data === 0){
  291 + return $data;
  292 + }
  293 + }
  294 +
282 } 295 }
283 } 296 }
284 $query = $this->query($sql); 297 $query = $this->query($sql);
@@ -146,47 +146,47 @@ class Mail { @@ -146,47 +146,47 @@ class Mail {
146 $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])])); 146 $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])]));
147 $pid = $pid ? $pid : 0; 147 $pid = $pid ? $pid : 0;
148 // try { 148 // try {
149 - $folder_name = '';  
150 - // 已发送  
151 - if(in_array('Send',$folder['check'])){  
152 - $folder_name = folderAlias('Send');  
153 - }  
154 - // 草稿  
155 - elseif(in_array('Drafts',$folder['check'])){  
156 - $folder_name = folderAlias('Drafts');  
157 - }  
158 - // 垃圾  
159 - elseif(in_array('Junk',$folder['check'])){  
160 - $folder_name = folderAlias('Junk');  
161 - }  
162 - // 回收站  
163 - elseif(in_array('Trash',$folder['check'])){  
164 - $folder_name = folderAlias('Trash');  
165 - } 149 + $folder_name = '';
  150 + // 已发送
  151 + if(in_array('Send',$folder['check'])){
  152 + $folder_name = folderAlias('Send');
  153 + }
  154 + // 草稿
  155 + elseif(in_array('Drafts',$folder['check'])){
  156 + $folder_name = folderAlias('Drafts');
  157 + }
  158 + // 垃圾
  159 + elseif(in_array('Junk',$folder['check'])){
  160 + $folder_name = folderAlias('Junk');
  161 + }
  162 + // 回收站
  163 + elseif(in_array('Trash',$folder['check'])){
  164 + $folder_name = folderAlias('Trash');
  165 + }
166 166
167 - if(!$folder_name){  
168 - $fn = explode('/',$folder['parseFolder']);  
169 - $folder_name = folderAlias(end($fn));  
170 - }  
171 - if(!$db->count(folderSql::has(['uuid'=>$uuid]))){  
172 - $db->insert(folderSql::$table,[  
173 - 'email_id' => $email_id,  
174 - 'folder' => folderAlias($folder_name),  
175 - 'origin_folder' => $folder['folder'],  
176 - 'uuid' => $uuid,  
177 - 'pid' => $pid  
178 - ],false);  
179 - }else{  
180 - $db->update(folderSql::$table,[  
181 - 'email_id' => $email_id,  
182 - 'folder' => folderAlias($folder_name),  
183 - 'origin_folder' => $folder['folder'],  
184 - 'uuid' => $uuid,  
185 - 'pid' => $pid  
186 - ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);  
187 - } 167 + if(!$folder_name){
  168 + $fn = explode('/',$folder['parseFolder']);
  169 + $folder_name = folderAlias(end($fn));
  170 + }
  171 + if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
  172 + $db->insert(folderSql::$table,[
  173 + 'email_id' => $email_id,
  174 + 'folder' => folderAlias($folder_name),
  175 + 'origin_folder' => $folder['folder'],
  176 + 'uuid' => $uuid,
  177 + 'pid' => $pid
  178 + ],false);
  179 + }else{
  180 + $db->update(folderSql::$table,[
  181 + 'email_id' => $email_id,
  182 + 'folder' => folderAlias($folder_name),
  183 + 'origin_folder' => $folder['folder'],
  184 + 'uuid' => $uuid,
  185 + 'pid' => $pid
  186 + ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);
  187 + }
188 // }catch (\Throwable $e){ 188 // }catch (\Throwable $e){
189 - // 这里就不处理失败了 189 + // 这里就不处理失败了
190 // } 190 // }
191 191
192 unset($folders[$fk]); 192 unset($folders[$fk]);
@@ -282,7 +282,8 @@ class Mail { @@ -282,7 +282,8 @@ class Mail {
282 282
283 $uids = array_column($uids,'UID'); 283 $uids = array_column($uids,'UID');
284 foreach ($uids as $k=>$uid){ 284 foreach ($uids as $k=>$uid){
285 - if($db->cache(86400*30)->value(listsSql::first(dbWhere(['email_id'=>$email_id,'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'))){ 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 +
286 unset($uids[$k]); 287 unset($uids[$k]);
287 } 288 }
288 } 289 }
@@ -444,7 +445,7 @@ class Mail { @@ -444,7 +445,7 @@ class Mail {
444 if(php_sapi_name()=='cli'){ 445 if(php_sapi_name()=='cli'){
445 go(function ($id,$header,$data){ 446 go(function ($id,$header,$data){
446 new syncMail($id,$header,$data); 447 new syncMail($id,$header,$data);
447 - }, 448 + },
448 ...[$id,$header,$data] 449 ...[$id,$header,$data]
449 ); 450 );
450 } 451 }