首页 > 解决方案 > Codeiginter 4 批量插入

问题描述

我正在使用 CI4 创建一个应用程序来读取包含超过 100K 记录的系列播放列表。

问题是它需要很多时间并且即使在添加后也会耗尽内存:

ini_set('memory_limit', '1024M');
ini_set('max_execution_time', -1);

好的,我可以增加 memory_limit,但仍然需要很多时间。

我使用以下方法插入数据库:

$this->db->transStart();
$seriesTable = $this->db->table('tbl_series');
$seriesTable->emptyTable();
$seriesTable->insertBatch($series);
$this->db->transComplete();

并且$series数组元素(情节)如下:

$epidose = array(
  'clm_series_name' => $station['author'],
  'clm_series_media_url' => $station['media_url'],
  'clm_series_group' => $station['group'],
  'clm_series_square' => $station['thumb_square'],
  'clm_series_type' => $station['type'],
  'clm_series_season' => $station['season'],
  'clm_series_episode' => $station['episode']
);

我想就如何减少执行时间提出建议。使用事务没有帮助。

有什么建议么?

标签: sqlitecodeigniter-4

解决方案


推荐阅读