-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: cache getTransaction result when sync in indexer mode
- Loading branch information
1 parent
c5b5c86
commit 756bd30
Showing
6 changed files
with
85 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/neuron-wallet/src/services/indexer/transaction-cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TransactionWithStatus } from "types/cell-types" | ||
|
||
export class TransactionCache { | ||
private limit: number | ||
|
||
private store = new Map<string, TransactionWithStatus>() | ||
|
||
constructor(limit: number) { | ||
this.limit = limit | ||
} | ||
|
||
public push(value: TransactionWithStatus) { | ||
const key = value.transaction.hash | ||
|
||
if (this.store.has(key)) { | ||
return | ||
} | ||
this.store.set(key, value) | ||
if (this.store.size > this.limit) { | ||
const firstKey = Array.from(this.store.keys())[0] | ||
this.store.delete(firstKey) | ||
} | ||
} | ||
|
||
public get(key: string): TransactionWithStatus | undefined { | ||
return this.store.get(key) | ||
} | ||
|
||
public delete(key: string): boolean { | ||
return this.store.delete(key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters