feat(gateway): improve GO API interface, remove Writable API#145
Conversation
Codecov Report
@@ Coverage Diff @@
## main ipfs/in-web-browsers#145 +/- ##
==========================================
+ Coverage 17.95% 18.28% +0.32%
==========================================
Files 94 94
Lines 10368 10181 -187
==========================================
Hits 1862 1862
+ Misses 8245 8058 -187
Partials 261 261
|
ac1614c to
43deb6b
Compare
|
I converted this to draft because I will be doing to more things: removing the Writable gateway and updating the interface to make it more simple. |
1e462b6 to
7c44868
Compare
| // Optimization: use Unixfs.Ls without resolving children, but using the | ||
| // cumulative DAG size as the file size. This allows for a fast listing | ||
| // while keeping a good enough Size field. | ||
| results, err := i.api.LsUnixFsDir(ctx, | ||
| resolvedPath, | ||
| options.Unixfs.ResolveChildren(false), | ||
| options.Unixfs.UseCumulativeSize(true), | ||
| ) |
There was a problem hiding this comment.
Moved this optimization to Kubo's codebase. Each gateway implementation should use whatever they want, some might be faster, some slower. It's the implementers choice. This also allowed me to simplify the API signature to remove the options.
- LsUnixFsDir(context.Context, path.Path, ...options.UnixfsLsOption) (<-chan iface.DirEntry, error)
+ LsUnixFsDir(context.Context, path.Resolved) (<-chan iface.DirEntry, error)
gateway/handler_unixfs_dir.go
Outdated
| idx, err := i.api.GetUnixFsNode(ctx, idxPath) | ||
| idxResolvedPath, err := i.api.ResolvePath(ctx, idxPath) | ||
| switch err.(type) { | ||
| case nil: | ||
| idx, err := i.api.GetUnixFsNode(ctx, idxResolvedPath) | ||
| if err != nil { | ||
| internalWebError(w, err) | ||
| return | ||
| } | ||
|
|
There was a problem hiding this comment.
I updated the signature of the getter for UnixFS files:
- GetUnixFsNode(context.Context, path.Path) (files.Node, error)
+ GetUnixFsNode(context.Context, path.Resolved) (files.Node, error)We already have ResolvePath at our disposal. Let's simplify. The change in this code is to reflect that.
lidel
left a comment
There was a problem hiding this comment.
Thank you @hacdias, moving Gateway.Writable to ipfs/kubo#9616 is 👍
Merging to unblock other PRs based on this.
| // Unixfs returns an implementation of Unixfs API | ||
| Unixfs() coreiface.UnixfsAPI | ||
| // API defines the minimal set of API services required for a gateway handler. | ||
| type API interface { |
There was a problem hiding this comment.
nit: something like IPFSBackend would be more descriptive, but can be changed later, won't block on this one thing (this interface will most likely get revamp in near future anyway)
Closes #61
This PR does the following:
NodeAPI(renamedAPI), such that we only require the bare minimum functions we need on the gateway. These have each the minimum required amount of functions required. This will allow other developers to use our gateway code much more easily.offlineAPIas a single function onAPI(IsCached).Please note: gateway sharness tests are expected to fail since they are run against Kubo's
masterversion. The PR in Kubo with this changes can be viewed at: ipfs/kubo#9616