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

chore: make $refreshTtl optional and re-order arguments for list push and dictionary increment #77

Merged
merged 7 commits into from
Dec 2, 2022

Conversation

poppoerika
Copy link
Contributor

  • Made $refreshTtl optional and default to true.
  • re-ordered arguments for list push and dictionary increment operations so that $trunncateFrontToSie, $truncateBackToSize, and amount are before $refreshTtl.
  • updated the tests to reflect the above changes.

This PR needs to get merged before working on #54.

Closes #49
Closes #50

…t list push operations and dictionary increment operation; updates tests accordingly
cprice404
cprice404 previously approved these changes Nov 28, 2022
Copy link
Collaborator

@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.

@poppoerika if you want to merge this as an incremental PR it looks good to me, but before we close #49 I wanted to make it conform to the pattern we established in the .NET repo, like this:

momentohq/client-sdk-dotnet-incubating#45

@poppoerika
Copy link
Contributor Author

@cprice404
As I implemented CollectionTtl, I wasn't entirely sure when to use withRefreshTtlOnUpdates.
If users want to refresh TTL on updates, it can be achieved by CollectionTtl::of(10) since $refreshTtl = true by default.
Maybe I'm missing something here.

@cprice404
Copy link
Collaborator

@cprice404 As I implemented CollectionTtl, I wasn't entirely sure when to use withRefreshTtlOnUpdates. If users want to refresh TTL on updates, it can be achieved by CollectionTtl::of(10) since $refreshTtl = true by default. Maybe I'm missing something here.

Good question. It's just there for API symmetry, in case people want to write very explicit code.

Copy link
Collaborator

@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.

i just have a couple of minor nits and then I'm +1. We should probably also get Pete to take a quick peek when he's back tomorrow.

@@ -175,6 +177,14 @@ private function ttlToMillis(?int $ttl = null): int
return $ttl * 1000;
}

private function returnCollectionTtl($ttl): CollectionTtl
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we annotate tye type of the argument here? I believe it would be ?CollectionTtl?


class CollectionTtl
{
private ?int $ttl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are using integers to represent ttls, the variable names need to include the unit for clarity. I think we were using ttlSeconds in the previous code.

cprice404
cprice404 previously approved these changes Nov 30, 2022
Copy link
Collaborator

@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.

✨ 🚢 from me!

but let's let pete take a quick peek

@@ -143,9 +144,9 @@ public function listErase(string $cacheName, string $listName, ?int $beginIndex
return $this->dataClient->listErase($cacheName, $listName, $beginIndex, $count);
}

public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, bool $refreshTtl, ?int $ttlSeconds = null): CacheDictionarySetFieldResponse
public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, CollectionTtl $ttl = null): CacheDictionarySetFieldResponse
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer the CollectionTtl parameter be explicitly nullable in all of these functions:

Suggested change
public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, CollectionTtl $ttl = null): CacheDictionarySetFieldResponse
public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, ?CollectionTtl $ttl = null): CacheDictionarySetFieldResponse

It looks like the null assignment does that implicitly, but I think making it explicit and consistent with the rest of our nullable parameters will make it more readable and maintainable.

@@ -271,18 +281,19 @@ public function listFetch(string $cacheName, string $listName): CacheListFetchRe
}

public function listPushFront(
string $cacheName, string $listName, string $value, bool $refreshTtl, ?int $truncateBackToSize = null, ?int $ttlSeconds = null
string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, CollectionTtl $ttl = null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above: please make all the CollectionTtl parameters in this file explicitly nullable ?CollectionTtl instead.

return new CollectionTtl(null, true);
}

public static function of(int $ttl): CollectionTtl
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd prefer this parameter to match the constructor and be called $ttlSeconds instead, so the unit is explicit in the parameter name (and in the named parameter label). I know I personally get confused about when we're using seconds vs. millis.

Copy link
Collaborator

@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.

This looks great! I made a couple small suggestions.

…to ?CollectionTtl; chore: rename of param to
Copy link
Collaborator

@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.

This is great, thanks you!

@poppoerika poppoerika merged commit b067f00 into main Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants