-
Notifications
You must be signed in to change notification settings - Fork 38
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
Emitting :key_deleted
when key is purged
#157
base: main
Are you sure you want to change the base?
Conversation
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.
Do you think there will ever be a case where someone cares about the difference between delete vs purge? I don't use the KV functionality much, so I'm not sure about the semantics of this API
I don't know go very well, but I think this bit of the go-client is exposing purge events separately from delete events? https://github.com/nats-io/nats.go/blob/9d4b227179d60d6996c32b4b889d4e325ee06f78/kv.go#L982-L989 |
@mmmries i just started using the KV so I’m not an expert. The end result is the same, the key is removed from the bucket (history stays when using del and removed when using purge). However, when the watcher process starts, you will still get historical events for a key that was deleted but not for a key that was purged. Edit |
headers | ||
|> Enum.filter(fn {k, v} -> | ||
k == @operation_header and (v == @operation_del or v == @operation_purge) | ||
end) | ||
|> length() > 0 |
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.
headers | |
|> Enum.filter(fn {k, v} -> | |
k == @operation_header and (v == @operation_del or v == @operation_purge) | |
end) | |
|> length() > 0 | |
Enum.any?(headers, fn {k, v} -> | |
k == @operation_header and (v == @operation_del or v == @operation_purge) | |
end) |
In practice this probably isn't a huge issue as written since the size of headers is probably small, but this is equivalent. At worst it makes a full pass once, at best it short-circuits early
headers | ||
|> Enum.filter(fn {k, v} -> | ||
k == @operation_header and (v == @operation_del or v == @operation_purge) | ||
end) | ||
|> length() > 0 |
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.
headers | |
|> Enum.filter(fn {k, v} -> | |
k == @operation_header and (v == @operation_del or v == @operation_purge) | |
end) | |
|> length() > 0 | |
Enum.any?(headers, fn {k, v} -> | |
k == @operation_header and (v == @operation_del or v == @operation_purge) | |
end) |
In practice this probably isn't a huge issue as written since the size of headers is probably small, but this is equivalent. At worst it makes a full pass once, at best it short-circuits early
@spec is_delete_operation?(headers :: Gnat.headers()) :: boolean() | ||
def is_delete_operation?(headers) do |
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.
@spec is_delete_operation?(headers :: Gnat.headers()) :: boolean() | |
def is_delete_operation?(headers) do | |
@spec delete_operation?(headers :: Gnat.headers()) :: boolean() | |
def delete_operation?(headers) do |
As an Elixir convention, using the ?
is correct for a function that returns a boolean, but the is_
prefix is reserved for guards. See https://hexdocs.pm/elixir/naming-conventions.html#trailing-question-mark-foo
:key_deleted
event is emitted when wither purging or deleting a keyFixes #156