aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-06 19:31:20 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-06 19:31:20 +0000
commitea69d02af6e691a1b32e5198a1143aa142ba82ac (patch)
treee3f78254c84e02cda30402fa6a179547f5d38f97 /models
parentfa52883f424c95dcde16e9056631041af4c479c7 (diff)
downloadcommunique-ea69d02af6e691a1b32e5198a1143aa142ba82ac.tar.gz
subscription lookup on outbox item create
Diffstat (limited to '')
-rw-r--r--models/persister.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/models/persister.go b/models/persister.go
index f877488..b4b9c49 100644
--- a/models/persister.go
+++ b/models/persister.go
@@ -98,6 +98,23 @@ func (p *Persister) Collect(model model) ([][]byte, error) {
return result, err
}
+// Much faster, "keys only" version of Collect()
+func (p *Persister) CollectKeys(model model) ([][]byte, error) {
+ var keys [][]byte
+ err := p.db.View(func(txn *badger.Txn) error {
+ opts := badger.DefaultIteratorOptions
+ opts.PrefetchValues = false
+ it := txn.NewIterator(opts)
+ defer it.Close()
+ prefix := []byte(model.Keybase())
+ for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
+ keys = append(keys, it.Item().Key())
+ }
+ return nil
+ })
+ return keys, err
+}
+
func (p *Persister) Find(model model) ([]byte, error) {
var result []byte
var item *badger.Item