From 5f553ec1f425c1c4628bd1e3c66c0ac41c6aeff4 Mon Sep 17 00:00:00 2001 From: scottf Date: Thu, 28 Oct 2021 16:31:49 -0400 Subject: [PATCH 1/4] ability to watch "withoutData", useful when retrieving keys --- kv.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kv.go b/kv.go index 58f4b4b95..aca1729f9 100644 --- a/kv.go +++ b/kv.go @@ -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 @@ -136,6 +138,14 @@ func IgnoreDeletes() WatchOpt { }) } +// WithoutData instructs the key watcher not retrieve message data +func WithoutData() WatchOpt { + return watchOptFn(func(opts *watchOpts) error { + opts.withoutData = true + return nil + }) +} + // KeyValueConfig is for configuring a KeyValue store. type KeyValueConfig struct { Bucket string @@ -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 @@ -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 From 73eb4330641e3a73b9f35a644c462b7ba6b7ff77 Mon Sep 17 00:00:00 2001 From: scottf Date: Thu, 28 Oct 2021 16:33:58 -0400 Subject: [PATCH 2/4] ability to watch "withoutData", useful when retrieving keys --- kv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kv.go b/kv.go index aca1729f9..dee7ece4e 100644 --- a/kv.go +++ b/kv.go @@ -122,7 +122,7 @@ func (opt watchOptFn) configureWatcher(opts *watchOpts) error { return opt(opts) } -// IncludeHistory instructs the key watcher to include historical values as well. +// IncludeHistory instructs the watcher to include historical values as well. func IncludeHistory() WatchOpt { return watchOptFn(func(opts *watchOpts) error { opts.includeHistory = true From 878768a6e7218f722e18d53f3bd1746613d531be Mon Sep 17 00:00:00 2001 From: scottf Date: Thu, 28 Oct 2021 16:35:07 -0400 Subject: [PATCH 3/4] ability to watch "withoutData", useful when retrieving keys --- kv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kv.go b/kv.go index dee7ece4e..aca1729f9 100644 --- a/kv.go +++ b/kv.go @@ -122,7 +122,7 @@ func (opt watchOptFn) configureWatcher(opts *watchOpts) error { return opt(opts) } -// IncludeHistory instructs the watcher to include historical values as well. +// IncludeHistory instructs the key watcher to include historical values as well. func IncludeHistory() WatchOpt { return watchOptFn(func(opts *watchOpts) error { opts.includeHistory = true From 5c9ca401dc56d3722bc566c71035e300c7160792 Mon Sep 17 00:00:00 2001 From: scottf Date: Fri, 29 Oct 2021 18:13:17 -0400 Subject: [PATCH 4/4] MetaOnly --- kv.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kv.go b/kv.go index aca1729f9..deaefde2a 100644 --- a/kv.go +++ b/kv.go @@ -112,8 +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 + // retrieve only the meta data of the entry + metaOnly bool } type watchOptFn func(opts *watchOpts) error @@ -138,10 +138,10 @@ func IgnoreDeletes() WatchOpt { }) } -// WithoutData instructs the key watcher not retrieve message data -func WithoutData() WatchOpt { +// MetaOnly instructs the key watcher to retrieve only the entry meta data, not the entry value +func MetaOnly() WatchOpt { return watchOptFn(func(opts *watchOpts) error { - opts.withoutData = true + opts.metaOnly = true return nil }) } @@ -544,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(), WithoutData()) + opts = append(opts, IgnoreDeletes(), MetaOnly()) watcher, err := kv.WatchAll(opts...) if err != nil { return nil, err @@ -686,7 +686,7 @@ func (kv *kvs) Watch(keys string, opts ...WatchOpt) (KeyWatcher, error) { if !o.includeHistory { subOpts = append(subOpts, DeliverLastPerSubject()) } - if o.withoutData { + if o.metaOnly { subOpts = append(subOpts, HeadersOnly()) } sub, err := kv.js.Subscribe(keys, update, subOpts...)