aa_ndrej
aa_ndrej
CDCloudflare Developers
Created by Max (@rozenmd) on 3/19/2024 in #d1-database
are you using db.batch?
Thank you very much!! 🎉 I needed to update a lot of data every now and then on a separate server. I tried using the REST API but there were limits (see https://discord.com/channels/595317990191398933/992060581832032316/1217528196074049589), then created basically a worker endpoint to chunk the data and send it do D1, which was significantly faster. Now I just changed this:
for (const entries of chunk(body, 50)) {
await db.insert(tempTable).values(entries)
}
for (const entries of chunk(body, 50)) {
await db.insert(tempTable).values(entries)
}
To this:
await db.batch(chunk(body, 50).map(entries =>
db.insert(tempTable).values(entries)
))
await db.batch(chunk(body, 50).map(entries =>
db.insert(tempTable).values(entries)
))
And insert time went from ~4:30min down to ~30s 🎉
1 replies