作者 邓超

h

... ... @@ -28,6 +28,12 @@ trait DbQuery {
*/
protected int $cache = 0;
/**
* 没有数据时 也缓存
* @var bool
*/
protected bool $cacheNoData = true;
public function getClient()
{
... ... @@ -51,8 +57,9 @@ trait DbQuery {
* @author:dc
* @time 2024/8/14 14:04
*/
public function cache(int $ttl){
public function cache(int $ttl,bool $noData = true){
$this->cache = $ttl;
$this->cacheNoData = $noData;
return $this;
}
... ... @@ -277,7 +284,13 @@ trait DbQuery {
$key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql));
if(redis()->has($key)){
$this->cache = 0;
return redis()->get($key,$default);
$data = redis()->get($key,$default);
if(!$this->cacheNoData){
if($data || $data === 0){
return $data;
}
}
}
}
$query = $this->query($sql);
... ...
... ... @@ -251,7 +251,7 @@ class Mail {
$blacklist = redis()->get('blacklist:'.$email_id);
$blackFolder = '';
if($blacklist){
$blackFolder = $db->value(folderSql::originFolder($email_id,'垃圾箱'));
$blackFolder = $db->cache(86400*30)->value(folderSql::originFolder($email_id,'垃圾箱'));
}
//
... ... @@ -281,11 +281,10 @@ class Mail {
$uids = array_column($uids,'UID');
$existsUids = $db->all(listsSql::getUids($email_id,$folder_id,$uids));
if($existsUids){
$existsUids = array_column($existsUids,'uid');
// 获取不存在数据库的uid
$uids = array_diff($uids,$existsUids);
foreach ($uids as $k=>$uid){
if($db->cache(86400*30,false)->value(listsSql::first(dbWhere(['email_id'=>$email_id,'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'))){
unset($uids[$k]);
}
}
... ... @@ -313,7 +312,7 @@ class Mail {
$unseen = $db->count(listsSql::listCount(dbWhere([
'seen' => 0,
'deleted' => 0,
'email_id' => $email_id,
// 'email_id' => $email_id,
'folder_id' => $folder_id,
])));
$db->update(
... ...