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

fix: reduce dagPb and dagCbor handler complexity #45

Merged

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Apr 8, 2024

Title

fix: reduce dagPb and dagCbor handler complexity

Description

fixes #43

  • create and use setIpfsRoots function
  • pull out walkPath logic into separate function

Notes & open questions

I'm not 100% sure about how to handle the isObjectNode === false case.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@SgtPooki SgtPooki requested a review from a team as a code owner April 8, 2024 19:37
@SgtPooki SgtPooki linked an issue Apr 8, 2024 that may be closed by this pull request
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

Comment on lines +270 to +272
// this should never happen, but if it does, we should log it and return notSupportedResponse
this.log.error('terminal element is not a dag-cbor node')
return notSupportedResponse(resource, 'Terminal element is not a dag-cbor node')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is the right thing to do here, or if we want to allow walking the path to fail and still query helia.blockstore.get(cid, options)

packages/verified-fetch/src/verified-fetch.ts Show resolved Hide resolved
@SgtPooki SgtPooki self-assigned this Apr 16, 2024
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

packages/verified-fetch/src/verified-fetch.ts Outdated Show resolved Hide resolved
export type RequestFormatShorthand = 'raw' | 'car' | 'tar' | 'ipns-record' | 'dag-json' | 'dag-cbor' | 'json' | 'cbor'

export type SupportedBodyTypes = string | ArrayBuffer | Blob | ReadableStream<Uint8Array> | null

export interface FetchHandlerFunctionArg {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: cacheKey was removed

* If a terminal element is not found, a notFoundResponse is returned
* If another unknown error occurs, a badGatewayResponse is returned
*/
export async function handlePathWalking ({ cid, path, resource, options, blockstore, log }: Omit<FetchHandlerFunctionArg, 'session'> & { blockstore: Blockstore, log: Logger }): Promise<PathWalkerResponse | Response> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was moved to walk-path.ts from verified-fetch.ts because that file is getting much too large

@@ -156,7 +126,8 @@ export class VerifiedFetch {
this.log.trace('created VerifiedFetch instance')
}

private getBlockstore (root: CID, key: string, useSession: boolean, options?: AbortOptions): Blockstore {
private getBlockstore (root: CID, resource: string | CID, useSession: boolean, options?: AbortOptions): Blockstore {
const key = resourceToSessionCacheKey(resource)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of constructing the key in fetch function, construct in here and just use the resource that FetchHandlerFunctionArg already has.

@SgtPooki SgtPooki merged commit 3b41752 into main May 16, 2024
20 checks passed
@SgtPooki SgtPooki deleted the 43-chore-reduce-line-complexity-in-handledagpb-and-handledagcbor branch May 16, 2024 20:21
github-actions bot pushed a commit that referenced this pull request May 16, 2024
## @helia/verified-fetch [1.4.2](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-1.4.1...@helia/verified-fetch-1.4.2) (2024-05-16)

### Bug Fixes

* reduce dagPb and dagCbor handler complexity ([#45](#45)) ([3b41752](3b41752))
Copy link

🎉 This PR is included in version 1.4.2 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 1.1.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 1.24.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: 🎉 Done
Development

Successfully merging this pull request may close these issues.

chore: reduce line complexity in handleDagPb and handleDagCbor
1 participant