-
Notifications
You must be signed in to change notification settings - Fork 6
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
chore: add fieldValueDictionary
accessor to dictionaryGetBatch
#65
Conversation
…ield-value pairs chore: add fieldsVal uesArray accessor to return an array containing field-value pairs
@@ -1020,6 +1024,11 @@ public function valuesArray(): array | |||
return $ret; | |||
} | |||
|
|||
public function fieldValueDictionary(): array |
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 think by our naming conventions this would start with value
. I think maybe it would be valueDictionary
but let's get @pgautier404 to weigh in.
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.
Yes, everything should begin with value
. I thought we were going to go with something like valueArray()
because dictionaries are arrays in PHP, but I could go with either name as long as it's consistent.
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.
See #65 (comment)
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.
and #65 (comment)
@@ -1020,6 +1024,11 @@ public function valuesArray(): array | |||
return $ret; |
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.
also i think we might want to change the name of valuesArray
to just responses
? Since it's not actually returning values directly, but rather, an array of objects that may have values in them?
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.
@cprice404 this actually is extracting the values from the responses and returning them.
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.
See #65 (comment)
src/Cache/_ScsDataClient.php
Outdated
@@ -576,7 +576,7 @@ public function dictionaryGetBatch(string $cacheName, string $dictionaryName, ar | |||
return new CacheDictionaryGetBatchResponseError(new UnknownError($e->getMessage())); | |||
} | |||
if ($dictionaryGetBatchResponse->hasFound()) { | |||
return new CacheDictionaryGetBatchResponseSuccess($dictionaryGetBatchResponse); | |||
return new CacheDictionaryGetBatchResponseSuccess($dictionaryGetBatchResponse, fields: $fields); |
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 think you have another PR up that may have conflicts with this one, yes? Where this class gets renamed to *DictionaryGetFields*
? Just calling it out to make sure that we end up with the correct one before the final merge.
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.
Yeah this is the PR for that: #64
@pgautier404 @cprice404
For 1, I think we can keep the name as is. Or we can rename this to |
The .NET SDK is returning responses without extracting values from them in a @cprice404 @malandis can you sanity check me here please? |
My intention for this API is that there will only be two accessors on this response type after we make the changes:
In .NET we will be removing the methods/properties for "accessing the extracted values as a list of strings or as a list of byte arrays". |
Got it.
Should I use |
It should start with |
I honestly couldn't speak for PHP devs other than myself, but I would personally prefer |
$this->responsesList[] = new CacheDictionaryGetFieldResponseMiss(); | ||
$this->responses[] = new CacheDictionaryGetFieldResponseHit(null, $response->getCacheBody()); | ||
$this->valuesDictionary[$fields[$counter]] = $response->getCacheBody(); | ||
$counter++; |
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'd like to ask you about this counter and about the numRequested param.
src/Cache/_ScsDataClient.php
Outdated
if ($dictionaryGetFieldsResponse->hasFound()) { | ||
return new CacheDictionaryGetFieldsResponseSuccess($dictionaryGetFieldsResponse, fields: $fields); | ||
} | ||
return new CacheDictionaryGetFieldsResponseSuccess(null, count($fields)); |
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 should be returning CacheDictionaryGetFieldsResponseHit
and CacheDictionaryGetFieldsResponseMiss
instead of trying to use the Success
class to represent two different states.
if (is_null($responses) && !is_null($numRequested)) { | ||
foreach (range(0, $numRequested - 1) as $ignored) { | ||
$this->responsesList[] = new CacheDictionaryGetFieldResponseMiss(); | ||
$this->responses[] = new CacheDictionaryGetFieldResponseMiss(); |
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 think all of this is the result of trying to use a Success
class where we need to be using Hit
and Miss
classes instead. I left a comment on _ScsDataClient
that lines up with this one.
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.
When I moved CacheDicitonaryGetBatch
from our .NET incubating repo, I referenced here, which has Success
and Error
as CacheDictionaryGetBatchResponse
.
Sorry if I missed, but are we going to update this response type to Hit
, Miss
, and Error
instead?
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.
You might double check with @cprice404 but I think this should follow the Hit/Miss/Error pattern since we're dealing with a single dictionary value and we can tell if our request was a miss in the corresponding data client code. It should also allow us to get rid of the $numRequested
parameter and logic in the CacheDictionaryGetFieldsResponseSuccess
constructor.
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 think I agree with @pgautier404 , I think this was an oversight when we were switching the .NET SDK over.
Here:
That code does not check for the "Missing" case that we got from the server. My gut is that it should be checking for that case, and should use Hit/Miss/Error pattern instead of success. That's what we do for DictionaryFetch, ListFech, etc. So we should fix that both in .NET and PHP. I created this ticket to capture it for .NET momentohq/client-sdk-dotnet-incubating#47 but yes let's go ahead and make this change here. @malandis if you know of any reason why DictionaryGetBatch/DictionaryGetFields shouldn't use Hit/Miss/Error pattern let us know.
I didn't review this closely enough to understand why that change would eliminate the need for the numRequested/counter thing but I also agree that it seems like we shouldn't need those, so if they still seem necessary after the switch to Hit/Miss/Error feel free to ping for 👀 .
Sorry for not catching this during the .NET work.
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.
@pgautier404 @cprice404 @malandis
My understanding is we want to have 4 different response patters:
- We found a dictionary and all items in the dictionary also found.
- We found a dictionary but some of the items in the dictionary are missing.
- We did not find a dictionary.
- We had an error finding a dictionary.
Cases 1, 3, 4 are straightforward.
1 -> Hit
3 -> Miss
4 -> Error
But how about case 2? Would this be Hit although some of the items are Miss?
So Hit means that finding a dictionary not necessarily the items inside?
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.
yes my opinion is that if the Dictionary itself is found, then case 2 is a HIT.
users may then check for individual fields by iterating over the responses
and seeing which are HIT vs MISS, or they can just use valueDictionary
and check to see if each key exists.
$counter = 0; | ||
parent::__construct(); |
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.
Kind of a nit, but the call to the parent constructor should pretty much always be the first line in a function:
$counter = 0; | |
parent::__construct(); | |
parent::__construct(); | |
$counter = 0; |
if ($response->getResult() == ECacheResult::Hit) { | ||
$this->responses[] = new CacheDictionaryGetFieldResponseHit(null, $response->getCacheBody()); | ||
$this->valuesDictionary[$fields[$counter]] = $response->getCacheBody(); | ||
} else if ($response->getResult() == ECacheResult::Miss) { |
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.
My IDE is telling me that PHP standards prefer elseif
.
} else if ($response->getResult() == ECacheResult::Miss) { | |
} elseif ($response->getResult() == ECacheResult::Miss) { |
I left a couple of notes on really minor changes but am good for this to merge once you have a chance to look at those! |
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.
LGTM!
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.
🚢
Added
fieldValueDictionary
accessor todictionaryGetBatch
to return an array of field/value pairs.Also, updated
dictionary
accessor tofieldValueDictionary
fordictionaryFetch
to be consistent with naming.Corresponding tests are also updated.
Closes #53