Skip to content

Commit

Permalink
fix: optimize update evm pubkey which has no pubkey only
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Oct 3, 2024
1 parent 3a0cc4d commit 7be710a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/services/evm/crawl_evm_account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,21 @@ export default class CrawlEvmAccountService extends BullableService {
})
);

const listAccountDB = await Account.query().whereIn(
'evm_address',
Object.keys(listAccountDict)
const listAccountDBByEvmAdd = _.keyBy(
await Account.query()
.select('id', 'evm_address', 'pubkey')
.whereIn('evm_address', Object.keys(listAccountDict)),
'evm_address'
);
const listAccount = Object.keys(listAccountDict).map((e) => ({
account: e,
pubkey: { type: 'jsonb', value: listAccountDict[e].pubkey },
address: listAccountDict[e].bech32Add,
id: listAccountDB.find((a) => a.evm_address === e)?.id,
}));
const listAccount = Object.keys(listAccountDict)
// filter account has no pubkey
.filter((e) => Object.keys(listAccountDBByEvmAdd[e].pubkey).length === 0)
.map((e) => ({
account: e,
pubkey: { type: 'jsonb', value: listAccountDict[e].pubkey },
address: listAccountDict[e].bech32Add,
id: listAccountDBByEvmAdd[e].id,
}));
await knex.transaction(async (trx) => {
if (listAccount.length > 0) {
await batchUpdate(trx, 'account', listAccount, ['pubkey', 'address']);
Expand Down

0 comments on commit 7be710a

Please sign in to comment.