public function get_data_for_adset()
    {
        while (true) {
            $ad = RedisDB::get_lPop(self::FB_ADSET_RDS);
            if(!$ad) break;
            if(!empty($ad['errNum']) && $ad['errNum'] >= 3){
                log_message('error','重新执行3次未成功:'.json_encode($ad));                
                continue;
            }            
            // 时间
            $starTime = date('Y-m-d',strtotime($ad['start_time']));
            $endTime  = date('Y-m-d',strtotime('-1 day', time()));
            if(!empty($ad['end_time'])) $endTime = date("Y-m-d",strtotime($ad['end_time']));
            // 请求参数拼接
            $url = self::JAVA_URL."/fb/adset/".$ad['adset_id']."/insights";
            $header = ['t:'.self::JAVA_TOKEN];
            $params = array(
                'id' => $ad['adset_id'],
                'accessToken'        => $this->access_token,
                'insights'           => [
                    "fields"         => 'account_id,campaign_id,adset_id,ad_id,account_name,campaign_name,adset_name,ad_name,impressions,clicks,spend,reach,actions,unique_actions',
                    "time_range"     => ["since"=>$starTime,"until"=>$endTime],
                    "reqAll"         => true,
                    "time_increment" => 1,
                    "level"          => 'adset',
                    'breakdowns' => $ad['breakdown'] == 1 ? 'country' : ''
                ],
            );
            $infoJson = _curl_post_json($url,$params,$header[0]);
            $info = json_decode($infoJson,true);

            if($info['code'] != 200){
                log_message('error','请求java失败，错误信息：'.$infoJson);
                $errContent = json_decode($info['content'],true);
                if($errContent['error']['code'] == 4 || $errContent['error']['code'] == 80000){
                    $ad['errNum'] += 1;
                    log_message('error','广告系列请求数据量过大，重新插入队列'.json_encode($ad));
                    // sleep(300);
                    RedisDB::rpush(self::FB_ADSET_RDS,serialize($ad));
                }
                continue;
            }
            if(count($info['content']) == 0){
                continue;
            }
            $insert = [];
            $upd = [];
            foreach ($info['content'] as $content) {
                $unique_actions = array_column($content['unique_actions'],'value','action_type');                
                $actions = array_column($content['actions'],'value','action_type');
                // 月份
                $month = date("Ym",strtotime($content['date_start']));
                // 类型
                if($ad['isExcel'] != 1){
                    $name = explode('_',$content['campaign_name']);
                    $type = strtolower($name[3]) == 'new' ? 2 : 1;                    
                }
                $insert[$month][] = [
                    'biz_date'          => date("Ymd",strtotime($content['date_start'])),
                    'type'              => $type ?? 3,
                    'report_rule_id'    => $ad['rule_id'],
                    'account_id'        => $content['account_id'],
                    'account_name'      => $content['account_name'],
                    'campaign_id'       => $content['campaign_id'],
                    'campaign_name'     => $content['campaign_name'],
                    'country'           => $content['country'] ?? '',
                    'adset_id'          => $content['adset_id'] ?? '',
                    'adset_name'        => $content['adset_name'] ?? '',
                    'ad_id'             => $content['ad_id'] ?? '',
                    'ad_name'           => $content['ad_name'] ?? '',
                    'impression'        => $content['impressions']  ?? 0,
                    'clicks'            => $content['clicks']  ?? 0,
                    'uo_click'          => $unique_actions['link_click']  ?? 0,
                    'spend'             => $content['spend']  ?? 0,
                    'link_click'        => $actions['link_click']  ?? 0,
                    'reach'             => $content['reach'] ?? 0,
                    'install'           => $actions['mobile_app_install'] ?? 0,
                    'unique_purchases'  => $unique_actions['omni_purchase'] ?? 0,
                ];

                // name补充
                $upd[$month] = [
                    'ad_name' => $content['ad_name'],
                    'adset_name' => $content['adset_name'],
                    'campaign_name' => $content['campaign_name'],
                    'account_name' => $content['account_name'],
                ];
            }
            
            if (!empty($insert)) {
                // 关闭再重启mysql
                $this->MonthDb_Z->db->close();
                $this->MonthDb_Z->db->initialize();
                $monthDb = $this->MonthDb_Z;
                foreach ($insert as $month => $add) {                    
                    $monthTable = $this->lk_ksh_fb.$month;
                    $monthDb->is_kshFbMonth_table($monthTable);
                    $monthDb->delete($monthTable, [
                        'biz_date >='    => date("Ymd", strtotime($starTime)),
                        'biz_date <='    => date("Ymd", strtotime($endTime)),
                        'report_rule_id' => $ad['rule_id'],
                        'adset_id'       => $ad['adset_id']
                    ]);
                    $monthDb->add_batch($monthTable, $add);
                }
            }
            if(!empty($upd)){
                // 关闭再重启mysql
                $this->MonthDb_Z->db->close();
                $this->MonthDb_Z->db->initialize();
                $monthDb = $this->MonthDb_Z;
                foreach ($upd as $month => $update) {                    
                    $monthTable = $this->lk_ksh_fb.$month;
                    if(!$monthDb->is_table($monthTable)){
                        continue;
                    }
                    $monthDb->update($monthTable,['adset_id'=>$ad['adset_id']],$update);
                }
            }
            unset($insert,$upd);
        }
    }怎么提升这个方法的效率