are you using db.batch?

are you using db.batch?
1 Reply
aa_ndrej
aa_ndrej•9mo ago
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 🎉
Want results from more Discord servers?
Add your server