作者 邓超

优化

@@ -41,7 +41,11 @@ class listsSql { @@ -41,7 +41,11 @@ class listsSql {
41 * @time 2023/3/17 16:24 41 * @time 2023/3/17 16:24
42 */ 42 */
43 public static function first($db,string $where,$filed='*', $throw=false) { 43 public static function first($db,string $where,$filed='*', $throw=false) {
44 - 44 + if(is_array($where)){
  45 + $where = dbWhere($where);
  46 + }elseif (is_numeric($where)) {
  47 + $where = dbWhere(['id' => $where]);
  48 + }
45 foreach ([self::$table,"lists_back","lists_hot"] as $table) { 49 foreach ([self::$table,"lists_back","lists_hot"] as $table) {
46 $sql = "select {$filed} from `".$table."` where ".$where.' limit 1'; 50 $sql = "select {$filed} from `".$table."` where ".$where.' limit 1';
47 if($throw){ 51 if($throw){
@@ -58,7 +62,31 @@ class listsSql { @@ -58,7 +62,31 @@ class listsSql {
58 } 62 }
59 63
60 64
  65 +
  66 +
  67 + public static function maxUid($db,string $where){
  68 + if(is_array($where)){
  69 + $where = dbWhere($where);
  70 + }elseif (is_numeric($where)) {
  71 + $where = dbWhere(['id' => $where]);
  72 + }
  73 + $uid = 0;
  74 + foreach ([self::$table,"lists_back",/*"lists_hot"*/] as $table) {
  75 + $sql = "select max(`uid`) as `mc` from `".$table."` where ".$where;
  76 + $data = $db->value($sql);
  77 + if($data) {
  78 + $uid = max($uid, $data);
  79 + }
  80 + }
  81 + return $uid;
  82 + }
  83 +
61 public static function count($db,string $where){ 84 public static function count($db,string $where){
  85 + if(is_array($where)){
  86 + $where = dbWhere($where);
  87 + }elseif (is_numeric($where)) {
  88 + $where = dbWhere(['id' => $where]);
  89 + }
62 $num = 0; 90 $num = 0;
63 foreach ([self::$table,"lists_back",/*"lists_hot"*/] as $table) { 91 foreach ([self::$table,"lists_back",/*"lists_hot"*/] as $table) {
64 $sql = "select count(*) as `mc` from `".$table."` where ".$where; 92 $sql = "select count(*) as `mc` from `".$table."` where ".$where;
@@ -455,15 +455,10 @@ class SyncMail { @@ -455,15 +455,10 @@ class SyncMail {
455 if($this->isStop) return $sync_number; 455 if($this->isStop) return $sync_number;
456 456
457 if($this->isUid){ 457 if($this->isUid){
458 - $maxUid = listsSql::first($this->db,dbWhere([ 458 + $maxUid = listsSql::maxUid($this->db,dbWhere([
459 'email_id'=>$this->emailId(), 459 'email_id'=>$this->emailId(),
460 'folder_id'=>$folder_id, 460 'folder_id'=>$folder_id,
461 - ]),'max(`uid`) as `uid`');  
462 - if($maxUid && $maxUid['uid']){  
463 - $maxUid = $maxUid['uid'];  
464 - }else {  
465 - $maxUid = 0;  
466 - } 461 + ]));
467 $maxUid = $maxUid?$maxUid:0; 462 $maxUid = $maxUid?$maxUid:0;
468 if($this->isUid==1&&!$maxUid){ 463 if($this->isUid==1&&!$maxUid){
469 return 0; 464 return 0;