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

perf(core-database): lookup wallets by keys #2810

Merged
merged 4 commits into from
Jul 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ export class WalletsBusinessRepository implements Database.IWalletsBusinessRepos
return this.search({ ...params, ...{ vote: publicKey } });
}

// @TODO: simplify this
public findById(id: string): State.IWallet {
return this.search().rows.find(
wallet => wallet.address === id || wallet.publicKey === id || wallet.username === id,
);
return this.databaseServiceProvider().walletManager.findById(id);
}

public count(): number {
Expand Down
2 changes: 2 additions & 0 deletions packages/core-interfaces/src/core-state/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface IWalletManager {

allByUsername(): IWallet[];

findById(id: string): IWallet;

findByAddress(address: string): IWallet;

has(addressOrPublicKey: string): boolean;
Expand Down
8 changes: 5 additions & 3 deletions packages/core-state/src/wallets/wallet-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class WalletManager implements State.IWalletManager {
return Object.values(this.byUsername);
}

public findById(id: string): State.IWallet {
return this.byAddress[id] || this.byPublicKey[id] || this.byUsername[id];
}

public findByAddress(address: string): State.IWallet {
if (address && !this.byAddress[address]) {
this.byAddress[address] = new Wallet(address);
Expand Down Expand Up @@ -310,9 +314,7 @@ export class WalletManager implements State.IWalletManager {

if (a.publicKey === b.publicKey) {
throw new Error(
`The balance and public key of both delegates are identical! Delegate "${
a.username
}" appears twice in the list.`,
`The balance and public key of both delegates are identical! Delegate "${a.username}" appears twice in the list.`,
);
}

Expand Down