Skip to content

Commit

Permalink
minor code review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
koresar committed Nov 29, 2023
1 parent 5bd9141 commit ab170c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion spec/book.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ describe("book", function () {
it("should reuse the snapshot listAccounts", async () => {
const book = new Book("MyBook-listAccounts-snapshot");
await addBalance(book);
// await snapshotListAccounts({ book: book.name, accounts: ["a", "b"], createdAt: new Date(), expireInSec: 1 });

await book.listAccounts();

Expand Down
10 changes: 4 additions & 6 deletions src/Book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function fromDistinctToAccounts(distinctResult: string[]) {
}
}

return accountsSet;
return Array.from(accountsSet);
}

export class Book<U extends ITransaction = ITransaction, J extends IJournal = IJournal> {
Expand Down Expand Up @@ -367,14 +367,12 @@ export class Book<U extends ITransaction = ITransaction, J extends IJournal = IJ
session: options.session,
})) as string[];

let accountsSet: Set<string> = fromDistinctToAccounts(results);
let uniqueAccounts = fromDistinctToAccounts(results);

if (listAccountsSnapshot) {
accountsSet = new Set([...accountsSet, ...listAccountsSnapshot.meta.accounts]);
uniqueAccounts = Array.from(new Set([...uniqueAccounts, ...listAccountsSnapshot.meta.accounts]));
}

const uniqueAccounts = Array.from(accountsSet);

if (uniqueAccounts.length === 0) return uniqueAccounts;

if (this.balanceSnapshotSec) {
Expand Down Expand Up @@ -408,7 +406,7 @@ export class Book<U extends ITransaction = ITransaction, J extends IJournal = IJ
.then((results) => {
return snapshotListAccounts({
book: this.name,
accounts: Array.from(fromDistinctToAccounts(results)),
accounts: fromDistinctToAccounts(results),
createdAt,
expireInSec: this.expireBalanceSnapshotSec,
});
Expand Down

0 comments on commit ab170c5

Please sign in to comment.