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: setBatch and getBatch #1153

Merged
merged 5 commits into from
Feb 27, 2024
Merged

feat: setBatch and getBatch #1153

merged 5 commits into from
Feb 27, 2024

Conversation

anitarua
Copy link
Contributor

@anitarua anitarua commented Feb 22, 2024

Adds batch get and set APIs for #674

Note: the streaming APIs use a different set of interceptors, this issue is still open: #349

Another note: this PR doesn't remove the nodejs batchutils functions

Copy link
Contributor

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

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

Overall this looks great! I just had a few minor questions / thoughts on the API. We should ask for a few more 👀 / opinions.

setBatch(
items:
| Record<string, string | Uint8Array>
| Map<string | Uint8Array, string | Uint8Array>,
Copy link
Contributor

Choose a reason for hiding this comment

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

i like how you did the types here to support both Record and Map!

* May contain nulls corresponding to cache misses.
* @returns {(string | undefined)[]}
*/
public values(): (string | undefined)[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should consider making the return type for this be a Record<string, string | uint>, or a Map.

I can definitely imagine cases where a user would just want them in order, but they could maybe achieve that sufficiently through results. It feels like the more natural / common / simple use case (which is what we want to prioritize for this .values function) might be to get back a structure that they can index into by key.

would really love to get other folks thoughts on this though, especially since is the first major SDK we're releasing this in and we will be treating it as a canonical example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I like that idea considering they provided a Record or Map, they're probably expecting a similar structure back.

I had missed this before but it seems like dictionaryGetFields returns items as Record or Map as well

Copy link
Contributor

@malandis malandis Feb 23, 2024

Choose a reason for hiding this comment

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

💯 on the record/map as the default. In the past when we have exposed an array (eg in earlier iterations of dictionaryGetFields), I believe we found the record/map easier to use. My intuition is users reach for the record/map first as well, and if you had an array you would zip it with the keys anyway. So this saves you that step.

Copy link
Contributor

@pgautier404 pgautier404 left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +782 to +809
call.on('data', (getResponse: grpcCache._GetResponse) => {
const result = getResponse.result;
switch (result) {
case grpcCache.ECacheResult.Hit:
results.push(new CacheGet.Hit(getResponse.cache_body));
break;
case grpcCache.ECacheResult.Miss:
results.push(new CacheGet.Miss());
break;
default:
results.push(
new CacheGet.Error(new UnknownError(getResponse.message))
);
}
});

call.on('end', () => {
resolve(new GetBatch.Success(results, keys));
});

call.on('error', (err: ServiceError | null) => {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new GetBatch.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

For the backlog: (1) the three callbacks -- data, end and error -- have boilerplate we can abstract away; and (2) we should require the developer to implement all three.

Otherwise 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@malandis wdym? is your comment targeted at future streaming APIs?

Copy link
Contributor

Choose a reason for hiding this comment

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

or just consolidating the get/set ones I guess?

Copy link
Contributor

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

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

batch

@anitarua anitarua merged commit 0e97ca9 into main Feb 27, 2024
13 checks passed
@anitarua anitarua deleted the batch-get-set branch February 27, 2024 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants