处理查询大数据的办法

1.第一种思路,查询分页,循环查询
public function run($itemId = '')
    {
        //查询出所有需要待更新的数据,分页处理
        $page = 1;
        $listingUpdate = new LazadaOnlineListingUpdate();
        $count = $listingUpdate->getCountByRawSql($this->type, $itemId);
        $totalPages = ceil($count / $this->limit);
        do {
            $offset = ($page - 1) * $this->limit;
            $data = $listingUpdate->getListByRawSql($this->type, $this->limit, $offset, $itemId);
            if (!empty($data)) {
                foreach ($data as $row) {
                    $this->updateProductStatus($row);
                }
            }
            $page++;
        } while ($page <= $totalPages);
    }

2.分块查询
查询的数据进行切割分块处理
foreach (collect($leafData)->chunk(100) as $child_collect) {
$object->updateBatch($child_collect->toArray());
}

 

posted on 2021-03-06 11:23  kevin_yang123  阅读(220)  评论(0编辑  收藏  举报