作者 邓超

同步到es脚本优化

... ... @@ -90,7 +90,7 @@ class SyncToEsCmd {
// 为文件夹打标 方便查询
$data['folder_as_int'] = folder2int($this->folders[$data['folder_id']]);
// postid ai邮箱要用 这个是查询黑格
list($data['postid'],$data['source']) = $this->getPostid($data['email_id']);
$data['postid'] = $this->getPostid($data['email_id']);
}catch (Throwable $e){
redis()->rPush('sync_to_es'.S_V2,$id);
_echo('sync to es '.$e->getMessage());
... ... @@ -115,23 +115,28 @@ class SyncToEsCmd {
}
protected $postids = [];
/**
* 查询项目id 和 邮件来源
* @param int $email_id 邮箱id
* @return array
* 项目id
* @author:dc
* @time 2025/5/29 11:47
* @time 2025/5/20 15:44
*/
public function getPostid($email_id){
$data = redis()->getSet('fob_bind_mail:'.$email_id,300,function ($email_id){
return $this->fob_db->throw()->first("select `post_id`,`source` from `e_mail_binds` where `email_id` = '{$email_id}' and `deleted_at` is null order by `id` desc limit 1");
},$email_id);
$h = date('dh');
if(!isset($this->postids[$h][$email_id])){
// 未删除状态
$id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' and `deleted_at` is null order by `id` desc limit 1 ");
if(!$id){
// 已删状态
$id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' order by `id` desc limit 1 ");
}
$this->postids[$h][$email_id] = $id;
}
return [
'postid' => $data['postid']??0,
'source' => $data['source']??0,
];
return $this->postids[$h][$email_id];
return 0;
}
... ...