Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize subql handler with bulk creation #646

Merged
merged 5 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bodhi/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
indent: [2, 2, { SwitchCase: 1 }],
quotes: [2, 'single'],
semi: [2, 'always'],
'no-trailing-spaces': [2],
'quote-props': [2, 'as-needed'],
'eol-last': [2, 'always'],
'object-curly-spacing': [2, 'always'],
Expand Down
1 change: 1 addition & 0 deletions eth-providers/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
indent: [2, 2, { SwitchCase: 1 }],
quotes: [2, 'single'],
semi: [2, 'always'],
'no-trailing-spaces': [2],
'quote-props': [2, 'as-needed'],
'eol-last': [2, 'always'],
'object-curly-spacing': [2, 'always'],
Expand Down
1 change: 1 addition & 0 deletions eth-rpc-adapter/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
indent: [2, 2, { SwitchCase: 1 }],
quotes: [2, 'single'],
semi: [2, 'always'],
'no-trailing-spaces': [2],
'quote-props': [2, 'as-needed'],
'eol-last': [2, 'always'],
'object-curly-spacing': [2, 'always'],
Expand Down
3 changes: 2 additions & 1 deletion eth-transactions/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ module.exports = {
rules: {
indent: [2, 2, { SwitchCase: 1 }],
quotes: [2, 'single'],
'quote-props': [2, 'as-needed'],
semi: [2, 'always'],
'no-trailing-spaces': [2],
'quote-props': [2, 'as-needed'],
'eol-last': [2, 'always'],
'object-curly-spacing': [2, 'always'],
'comma-dangle': [2, {
Expand Down
2 changes: 2 additions & 0 deletions evm-subql/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/types/
dist/
1 change: 1 addition & 0 deletions evm-subql/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
indent: [2, 2, { SwitchCase: 1 }],
quotes: [2, 'single'],
semi: [2, 'always'],
'no-trailing-spaces': [2],
'quote-props': [2, 'as-needed'],
'eol-last': [2, 'always'],
'object-curly-spacing': [2, 'always'],
Expand Down
25 changes: 16 additions & 9 deletions evm-subql/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import '@polkadot/api-augment';
import { parseReceiptsFromBlockData } from '@acala-network/eth-providers/lib/utils';
import { SubstrateBlock } from '@subql/types';
import { Log, TransactionReceipt } from '../types';

export const handleBlock = async (substrateBlock: SubstrateBlock): Promise<void> => {
const receipts = await parseReceiptsFromBlockData(
Expand All @@ -10,12 +9,15 @@ export const handleBlock = async (substrateBlock: SubstrateBlock): Promise<void>
substrateBlock.events,
);

for (const [idx, receipt] of receipts.entries()) {
const blockNumber = substrateBlock.block.header.number.toBigInt();
const receiptEntities = [];
const logEntities = [];

receipts.forEach((receipt, idx) => {
const receiptId = `${receipt.blockNumber.toString()}-${idx}`;
const transactionIndex = BigInt(receipt.transactionIndex);
const blockNumber = BigInt(receipt.blockNumber);

await TransactionReceipt.create({

receiptEntities.push({
...receipt,
id: receiptId,
gasUsed: receipt.gasUsed.toBigInt(),
Expand All @@ -25,16 +27,21 @@ export const handleBlock = async (substrateBlock: SubstrateBlock): Promise<void>
status: BigInt(receipt.status),
transactionIndex,
blockNumber,
}).save();
});

await store.bulkCreate('Log', receipt.logs.map(log => ({
receipt.logs.forEach(log => logEntities.push({
...log,
id: `${receiptId}-${log.logIndex}`,
receiptId,
transactionIndex,
blockNumber,
logIndex: BigInt(log.logIndex),
removed: false, // this field was removed by formatter.receipt...
})));
}
}));
});

await Promise.all([
store.bulkCreate('TransactionReceipt', receiptEntities),
store.bulkCreate('Log', logEntities),
]);
};
Loading