Skip to content

Commit

Permalink
feat: reenable cache (#4566)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglonghong authored Jun 21, 2023
1 parent 1411cc1 commit bf26efb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/adapters/database/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ export const getSpokeNodes = async (
start: number,
end: number,
count: number,
pageSize = 100000,
pageSize = 10000,
_pool?: Pool | db.TxnClientForRepeatableRead,
): Promise<string[]> => {
const poolToUse = _pool ?? pool;
Expand Down Expand Up @@ -1066,7 +1066,7 @@ export const getHubNodes = async (
start: number,
end: number,
count: number,
pageSize = 100000,
pageSize = 10000,
_pool?: Pool | db.TxnClientForRepeatableRead,
): Promise<string[]> => {
const poolToUse = _pool ?? pool;
Expand Down
26 changes: 12 additions & 14 deletions packages/utils/src/helpers/merkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,18 @@ export class SparseMerkleTree {
// Get the subtree down the opposite path of the one to the target.
const nodes = await this.getSubtreeNodes(depth + 1, siblingPath);

siblings[depth] = this.getSubtreeRoot(depth + 1, nodes);

// // Use cached root for path if available
// const cachedRoot = await this.db.getRoot(siblingPath);
// if (cachedRoot) {
// siblings[depth] = cachedRoot;
// } else {
// // The sibling at this depth will be the root of that subtree.
// siblings[depth] = this.getSubtreeRoot(depth + 1, nodes);

// // Cache the subtree in the DB once we have solved for root.
// const expectedNodeCount = 2 ** (this.height - (depth + 1));
// if (expectedNodeCount - nodes.length === 0) await this.db.putRoot(siblingPath, siblings[depth]);
// }
// Use cached root for path if available
const cachedRoot = await this.db.getRoot(siblingPath);
if (cachedRoot) {
siblings[depth] = cachedRoot;
} else {
// The sibling at this depth will be the root of that subtree.
siblings[depth] = this.getSubtreeRoot(depth + 1, nodes);

// Cache the subtree in the DB once we have solved for root.
const expectedNodeCount = 2 ** (this.height - (depth + 1));
if (expectedNodeCount - nodes.length === 0) await this.db.putRoot(siblingPath, siblings[depth]);
}
}

// Get the last sibling node.
Expand Down

0 comments on commit bf26efb

Please sign in to comment.