-
Notifications
You must be signed in to change notification settings - Fork 344
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: add new option for bulk gets in KV #3628
base: main
Are you sure you want to change the base?
Conversation
All contributors have signed the CLA ✍️ ✅ |
6e63cdc
to
44f5025
Compare
I have read the CLA Document and I hereby sign the CLA |
recheck |
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.
Good work! Left some comments with suggestions to improve tests.
src/workerd/api/kv-test.js
Outdated
const decoder = new TextDecoder(); // UTF-8 by default | ||
let r = ""; | ||
while (true) { | ||
const { done, value } = await reader.read(); |
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 - any particular reason for doing this in stream, instead of just doing request.arrayBuffer()
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.
Tried some other ways and it was not reading the stream properly. Both here and in the type "stream" test below.
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.
Can you expand on what "not reading the stream properly" means? ;-)
Also... you can do the following to simplify this a bit:
for await (const chunk of request.body) {
r += decoder.decode(value, { stream: true });
}
// But also remember to grab the final buffered chunk if any.
r += decoder.decode();
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 did not try this one in particular. Added it, thank you!
ff830c5
to
39f063b
Compare
if(parsedBody.type == "json") { | ||
for(const key of keys) { | ||
if(key == "key-not-json") { | ||
return new Response(null, {status: 500}) |
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.
fwiw, We have Response.error()
now that would end up sending a 500 response back to the eyeball.
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.
Tried this one but the error message would be more generic and less specific to our particular case, so I would rather keep it like it is, if that's ok.
src/workerd/api/kv-test.js
Outdated
assert.ok(false); | ||
} catch { | ||
assert.ok(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.
If the expectation is that the env.KV.get promise will reject, use
await assert.rejects(env.KV.get('fail-server'), {
message: '... whatever the expected error message is',
});
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.
This is so much cleaner. Thanks a bunch!
And thanks for all the suggestions :)
src/workerd/api/kv-test.js
Outdated
let result = ""; | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) break; | ||
result += decoder.decode(value, { stream: 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.
let result = ""; | |
while (true) { | |
const { done, value } = await reader.read(); | |
if (done) break; | |
result += decoder.decode(value, { stream: true }); | |
} | |
let result = ""; | |
for await (const chunk of response) { | |
result += decoder.decode(value, { stream: true }); | |
} | |
result += decoder.decode(); |
jsg::Promise<KvNamespace::GetWithMetadataResult> KvNamespace::getWithMetadataSingle( | ||
jsg::Lock& js, kj::String name, jsg::Optional<kj::OneOf<kj::String, GetOptions>> options) { | ||
return getWithMetadataImpl(js, kj::mv(name), kj::mv(options), LimitEnforcer::KvOpType::GET_WITH); | ||
} |
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.
Be sure to check the linting. Looks like the indentation on a few of these is out of whack.
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.
That line in particular was already here, but I agree that it seems generally funky. Tried to adjust it a bit. Is there a linter I can run on top of this?
Thank you!
02c9cc8
to
7e8640a
Compare
7e8640a
to
804c58c
Compare
Creating a new part in the binding for new bulk gets, along with tests for regular gets and the bulk gets
We consider we have a POST endpoint in SGW and we send the keys in a json format as such:
However, we decided that the binding here will only be a passthrough and everything will processed in the endpoint. On top of that, since everything is processed in the binding and comes as a single response, we don't need extra logic to process metadata, we just need to make sure that the binding responds what we what. Because of these two things, we added two more parameters in the request body:
We added tests for:
Regular gets:
Bulk Gets:
Note that we do not test for 400s because we will not have them. If none of the keys exist, we return a 200 but with empty values. Example: