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

feat: reenable cache #4566

Merged
merged 1 commit into from
Jun 21, 2023
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
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