-
Notifications
You must be signed in to change notification settings - Fork 97
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(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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for identifying these @hacdias.
I've dropped some ideas to simplify it further + avoid confusing names + follow up for cleaning up writable mode in Kubo.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.offlineAPI
as a single function onAPI
(IsCached
).Please note: gateway sharness tests are expected to fail since they are run against Kubo's
master
version. The PR in Kubo with this changes can be viewed at: ipfs/kubo#9616