Skip to content

Commit 6e36550

Browse files
committed
feat: Optimize output db query
1 parent 9de193b commit 6e36550

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {MigrationInterface, QueryRunner, TableIndex} from "typeorm";
2+
3+
export class AddOutputIndex1572226722928 implements MigrationInterface {
4+
5+
public async up(queryRunner: QueryRunner): Promise<any> {
6+
await queryRunner.createIndex("output", new TableIndex({ columnNames: ["lockHash", "status", "hasData", "typeScript"] }))
7+
}
8+
9+
public async down(queryRunner: QueryRunner): Promise<any> {
10+
await queryRunner.dropIndex("output", new TableIndex({ columnNames: ["lockHash", "status", "hasData", "typeScript"] }))
11+
}
12+
13+
}

packages/neuron-wallet/src/database/chain/ormconfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ChangeHasDataDefault1568621556467 } from './migrations/1568621556467-Ch
1515
import { AddLockToInput1570522869590 } from './migrations/1570522869590-AddLockToInput'
1616
import { AddIndices1572006450765 } from './migrations/1572006450765-AddIndices'
1717
import { AddIndexToTxTimestamp1572137226866 } from './migrations/1572137226866-AddIndexToTxTimestamp'
18+
import { AddOutputIndex1572226722928 } from './migrations/1572226722928-AddOutputIndex'
1819

1920
export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError'
2021

@@ -41,7 +42,8 @@ const connectOptions = async (genesisBlockHash: string): Promise<SqliteConnectio
4142
ChangeHasDataDefault1568621556467,
4243
AddLockToInput1570522869590,
4344
AddIndices1572006450765,
44-
AddIndexToTxTimestamp1572137226866
45+
AddIndexToTxTimestamp1572137226866,
46+
AddOutputIndex1572226722928
4547
],
4648
logging,
4749
maxQueryExecutionTime: 30

packages/neuron-wallet/src/services/cells.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ export default class CellsService {
2828

2929
const cells: OutputEntity[] = await getConnection()
3030
.getRepository(OutputEntity)
31-
.find({
32-
where: queryParams,
33-
})
31+
.createQueryBuilder('output')
32+
.select([
33+
"output.lockHash",
34+
"output.status",
35+
"output.hasData",
36+
"output.typeScript",
37+
"output.capacity"
38+
])
39+
.where(queryParams)
40+
.getMany()
3441

3542
const capacity: bigint = cells.map(c => BigInt(c.capacity)).reduce((result, c) => result + c, BigInt(0))
3643

0 commit comments

Comments
 (0)