作者 邓超

x

... ... @@ -7,6 +7,7 @@ namespace Controller\fob_ai;
use Controller\Base;
use Lib\Verify;
use Model\folderSql;
use function Swoole\Coroutine\Http\request;
/**
* 黑格 fob 那边专用 业务
... ... @@ -188,7 +189,7 @@ class MailList extends Base {
},$lists?:[]);
// 总数
$total = db()->count(sprintf($sql,"count(*)"));
$total = db()->cache(600)->count(sprintf($sql,"count(*)"));
app()->_json(listsPage($lists,$total,$page,$limit));
... ... @@ -220,42 +221,42 @@ class MailList extends Base {
$where['lists|folder_id'] = $this->getFolderId('发件箱');
// 预热发件箱
$where['fob_hot_mail|folder'] = 'f';
$fCount = db()->count($sql.dbWhere($where));
$fCount = db()->cache(600)->count($sql.dbWhere($where));
}
// 预热收件箱
if(in_array('hot_inbox',$show_count_filed)) {
$where['lists|folder_id'] = $this->getFolderId('收件箱');
$where['fob_hot_mail|folder'] = 's';
$sCount = db()->count($sql . dbWhere($where));
$sCount = db()->cache(600)->count($sql . dbWhere($where));
}
unset($where['fob_hot_mail|folder']);
$sql = $sql." ISNULL(`lists_id`) and ";
if(in_array('send',$show_count_filed)) {
$where['lists|folder_id'] = $this->getFolderId('发件箱');
$faCount = db()->count($sql . dbWhere($where));
$faCount = db()->cache(600)->count($sql . dbWhere($where));
}
// 垃圾箱
if(in_array('junk',$show_count_filed)) {
$where['lists|folder_id'] = $this->getFolderId('垃圾箱');
$lajiCount = db()->count($sql . dbWhere($where));
$lajiCount = db()->cache(600)->count($sql . dbWhere($where));
}
// 收件箱
if(in_array('inbox',$show_count_filed)) {
$where['lists|folder_id'] = $this->getFolderId('收件箱');
$shouCount = db()->count($sql . dbWhere($where));
$shouCount = db()->cache(600)->count($sql . dbWhere($where));
}
// 未读
if(in_array('unseen',$show_count_filed)) {
$where['seen'] = 0;
$seenCount = db()->count($sql . dbWhere($where));
$seenCount = db()->cache(600)->count($sql . dbWhere($where));
unset($where['seen']);
}
// 星标
if(in_array('flagged',$show_count_filed)) {
$where['flagged'] = 1;
$flaggedCount = db()->count($sql . dbWhere($where));
$flaggedCount = db()->cache(600)->count($sql . dbWhere($where));
}
$data = [];
if(isset($shouCount)) $data['inbox'] = $shouCount;
... ...
... ... @@ -22,6 +22,12 @@ trait DbQuery {
*/
protected $isThrow = false;
/**
* 是否缓存
* @var int
*/
protected int $cache = 0;
public function getClient()
{
... ... @@ -38,6 +44,18 @@ trait DbQuery {
return $this;
}
/**
* 是否缓存结果
* @param int $ttl
* @return $this
* @author:dc
* @time 2024/8/14 14:04
*/
public function cache(int $ttl){
$this->cache = $ttl;
return $this;
}
/**
* 查询
... ... @@ -206,9 +224,19 @@ trait DbQuery {
* @time 2023/2/14 16:19
*/
public function count(string|array $sql):int{
if($this->cache){
$key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql));
if(redis()->has($key)){
return redis()->get($key,0);
}
}
$query = $this->query($sql);
if($query){
return $query->fetch(\PDO::FETCH_COLUMN);
$count = $query->fetch(\PDO::FETCH_COLUMN);
if($this->cache){
redis()->set($key,$count,$this->cache);
}
return $count;
}
return 0;
}
... ...