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

ability to watch "withoutData", useful when retrieving keys #854

Merged
merged 4 commits into from Oct 31, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion kv.go
Expand Up @@ -112,6 +112,8 @@ type watchOpts struct {
ignoreDeletes bool
// Include all history per subject, not just last one.
includeHistory bool
// Don't watch (retrieve) the data
withoutData bool
}

type watchOptFn func(opts *watchOpts) error
Expand All @@ -136,6 +138,14 @@ func IgnoreDeletes() WatchOpt {
})
}

// WithoutData instructs the key watcher not retrieve message data
func WithoutData() WatchOpt {
Copy link
Member

Choose a reason for hiding this comment

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

We called this HeadersOnly for the consumers. That may not be the right answer here but this feels weird.

Maybe KeysOnly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted HeadersOnly, but that name already declared in the package. Although I originally though of this as a way to improve the Keys() method performance, I realized that it would not be unreasonable for someone to just watch the key and not care about the value change, just the state change, which comes in the headers. Maybe StateOnly? EntryStateOnly? MetaOnly, EntryMetaOnly?

Copy link
Member

Choose a reason for hiding this comment

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

I would be ok with any of the following. Will let you and @ripienaar decide ;)

KeysOnly
MetaOnly
OnlyKeys
OnlyMeta

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My 1st choice is MetaOnly, 2nd is OnlyMeta. I think Keys isn't correct as we will end up returning an entry object with everything except the value, the "meta" part of the entry as described in the ADR.

return watchOptFn(func(opts *watchOpts) error {
opts.withoutData = true
return nil
})
}

// KeyValueConfig is for configuring a KeyValue store.
type KeyValueConfig struct {
Bucket string
Expand Down Expand Up @@ -534,7 +544,7 @@ func (kv *kvs) PurgeDeletes(opts ...WatchOpt) error {

// Keys() will return all keys.
func (kv *kvs) Keys(opts ...WatchOpt) ([]string, error) {
opts = append(opts, IgnoreDeletes())
opts = append(opts, IgnoreDeletes(), WithoutData())
watcher, err := kv.WatchAll(opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -676,6 +686,9 @@ func (kv *kvs) Watch(keys string, opts ...WatchOpt) (KeyWatcher, error) {
if !o.includeHistory {
subOpts = append(subOpts, DeliverLastPerSubject())
}
if o.withoutData {
subOpts = append(subOpts, HeadersOnly())
}
sub, err := kv.js.Subscribe(keys, update, subOpts...)
if err != nil {
return nil, err
Expand Down