javascript - 将 Salesforce 批量 api 数据解析成块进行处理
问题描述
我有下面的代码,我从 Bulk APi 查询作业中获取结果,其中记录数量巨大(60,000 到 80,000)。我将其转换为 JSON 并将插入到数据库中。任何人都可以建议处理大量数据的最佳方法以及如何分块处理它。
request.get( options, function ( error, response, body ) {
if ( error )
{
} else
{
csvJson()
.fromString( response.body )
.then( ( jsonObj ) => {
var a = JSON.stringify( jsonObj );
} )
}
} );
解决方案
async function* readApi() {
let page = 1;
while (page != null) {
const r = await fetch(`http://target-api.com/stuff?page=${page}`)
const d = await r.json()
page = yield d
}
}
const it = readApi()
it.next() // Init fn with first next call it will get the first page
it.next(2) // Gets the second page, process the data and go to next call
// ..
// ..
it.next(null) // When you are done with getting data call with null
推荐阅读
- reactjs - 处理多个数字类型输入
- python - 如何以“正常”方式对包括 str 和编号的数据进行排序 [Python]
- android - 如何在不使用 C 的情况下使用 aarch64 打印数字
- arrays - 使用扁平化!在数组数组上不起作用
- ruby-on-rails - 如何通过 webpacker 将 jstree 添加到 Rails
- java - DataBindig 向布局返回错误的 onFocusChangeListener
- facebook - 我们应该向我们的网站添加 Open Graph 元属性吗?
- xamarin - 打开自定义过滤 UI 时 RadDataGrid 的高度发生变化
- android - 发布 APK 版本未更新
- javascript - Wheelnav:有没有办法重置或调用物品的悬停效果?