diff --git a/package-lock.json b/package-lock.json index a290763..7f3ebef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "groundcontrol", - "version": "2.3.3", + "version": "2.3.4", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index d832ace..23088b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "groundcontrol", - "version": "2.3.3", + "version": "2.3.4", "description": "GroundControl push server API", "devDependencies": { "@types/node": "18.7.16", diff --git a/src/worker-blockprocessor.ts b/src/worker-blockprocessor.ts index cd20244..57bb2d5 100644 --- a/src/worker-blockprocessor.ts +++ b/src/worker-blockprocessor.ts @@ -66,6 +66,7 @@ async function processBlock(blockNum, sendQueueRepository: Repository const query = dataSource.getRepository(TokenToAddress).createQueryBuilder().where("address IN (:...address)", { address: addresses }); + let entities2save = []; for (const t2a of await query.getMany()) { // found all addresses that we are tracking on behalf of our users. now, // iterating all addresses in a block to see if there is a match. @@ -79,15 +80,24 @@ async function processBlock(blockNum, sendQueueRepository: Repository payload.token = t2a.token; payload.type = 2; payload.badge = 1; - await sendQueueRepository.save({ + entities2save.push({ data: JSON.stringify(payload), }); } } } + // batch insert via a raw query as its faster + await sendQueueRepository + .createQueryBuilder() + .insert() + .into(SendQueue) + .values(entities2save) + .execute(); + // now, checking if there is a subscription to one of the mined txids: const query2 = dataSource.getRepository(TokenToTxid).createQueryBuilder().where("txid IN (:...txids)", { txids }); + entities2save = []; for (const t2txid of await query2.getMany()) { const payload: components["schemas"]["PushNotificationTxidGotConfirmed"] = { txid: t2txid.txid, @@ -99,10 +109,19 @@ async function processBlock(blockNum, sendQueueRepository: Repository }; process.env.VERBOSE && console.log("enqueueing", payload); - await sendQueueRepository.save({ + entities2save.push({ data: JSON.stringify(payload), }); } + + + // batch insert via a raw query as its faster + await sendQueueRepository + .createQueryBuilder() + .insert() + .into(SendQueue) + .values(entities2save) + .execute(); } dataSource