作者 邓超

x

@@ -275,6 +275,32 @@ class SyncMail { @@ -275,6 +275,32 @@ class SyncMail {
275 ],'`id`')); 275 ],'`id`'));
276 } 276 }
277 277
  278 + /**
  279 + * 过滤uid
  280 + * @param array $uids
  281 + * @return array
  282 + * @author:dc
  283 + * @time 2024/11/12 14:17
  284 + */
  285 + private function getFilterUid(array $uids, int $folder_id):array {
  286 + foreach ($uids as $k=>$uid){
  287 +
  288 + $num = redis()->get('h_'.$folder_id.'_'.$uid,function () use ($folder_id,$uid){
  289 + $num = $this->db->value(listsSql::first(dbWhere(['email_id'=>$this->emailId(),'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'));
  290 + if($num){
  291 + redis()->set('h_'.$folder_id.'_'.$uid,1,86400);
  292 + }
  293 + return $num;
  294 + });
  295 +
  296 + if($num){
  297 + unset($uids[$k]);
  298 + }
  299 + }
  300 +
  301 + return array_values($uids);
  302 + }
  303 +
278 /**同步邮件 304 /**同步邮件
279 * 305 *
280 * @param string|\Lib\Imap\Request\Folder $folder 306 * @param string|\Lib\Imap\Request\Folder $folder
@@ -308,26 +334,10 @@ class SyncMail { @@ -308,26 +334,10 @@ class SyncMail {
308 $uids = $msg->forPage($p)->getOriginUids(); 334 $uids = $msg->forPage($p)->getOriginUids();
309 } 335 }
310 336
  337 + $uids = $this->getFilterUid($uids,$folder_id);
  338 +
311 if($uids){ 339 if($uids){
312 $p++; 340 $p++;
313 -  
314 - foreach ($uids as $k=>$uid){  
315 -  
316 - $num = redis()->get('h_'.$folder_id.'_'.$uid,function () use ($folder_id,$uid){  
317 - $num = $this->db->value(listsSql::first(dbWhere(['email_id'=>$this->emailId(),'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'));  
318 - if($num){  
319 - redis()->set('h_'.$folder_id.'_'.$uid,1,86400);  
320 - }  
321 - return $num;  
322 - });  
323 -  
324 - if($num){  
325 - unset($uids[$k]);  
326 - }  
327 - }  
328 -  
329 - if(!$uids) continue;  
330 -  
331 $lists = $msg->uid($uids)->get()->all(); 341 $lists = $msg->uid($uids)->get()->all();
332 $sync_number += count($lists); 342 $sync_number += count($lists);
333 // 没有数据就跳出 343 // 没有数据就跳出
@@ -337,7 +347,7 @@ class SyncMail { @@ -337,7 +347,7 @@ class SyncMail {
337 }else{ 347 }else{
338 break; 348 break;
339 } 349 }
340 - 350 + // 只需要执行一次
341 if ($this->search instanceof ImapSearch){ 351 if ($this->search instanceof ImapSearch){
342 break; 352 break;
343 } 353 }