@cryptotaxi247 / kubo / commits / 906d2bd09

Don't do extra work in provider queue loop

License: MIT Signed-off-by: Erik Ingenito <erik@carbonfive.com>

Erik Ingenito committed Mar 16, 2019 at 09:52 UTC 906d2bd093fc8f6776cf80f81f2a363ad5006ec8
1 file changed +13 -7
provider/queue.go
+13 -7
@@ -2,13 +2,14 @@ package provider
2
3 import (
4 "context"
5 - "github.com/ipfs/go-cid"
6 - "github.com/ipfs/go-datastore"
7 - "github.com/ipfs/go-datastore/namespace"
8 - "github.com/ipfs/go-datastore/query"
5 "math"
6 "strconv"
7 "strings"
8 +
9 + cid "github.com/ipfs/go-cid"
10 + datastore "github.com/ipfs/go-datastore"
11 + namespace "github.com/ipfs/go-datastore/namespace"
12 + query "github.com/ipfs/go-datastore/query"
13 )
14
15 // Queue provides a durable, FIFO interface to the datastore for storing cids
@@ -100,11 +101,16 @@ func (q *Queue) nextEntry() (datastore.Key, cid.Cid) {
101 // Run dequeues and enqueues when available.
102 func (q *Queue) work() {
103 go func() {
104 + var k datastore.Key = datastore.Key{}
105 + var c cid.Cid = cid.Undef
106
107 for {
105 - k, c := q.nextEntry()
106 - var dequeue chan cid.Cid
108 + if c == cid.Undef {
109 + k, c = q.nextEntry()
110 + }
111
112 + // If c != cid.Undef set dequeue and attempt write, otherwise wait for enqueue
113 + var dequeue chan cid.Cid
114 if c != cid.Undef {
115 dequeue = q.dequeue
116 }
@@ -126,7 +132,7 @@ func (q *Queue) work() {
132 log.Errorf("Failed to delete queued cid %s with key %s: %s", c, k, err)
133 continue
134 }
129 -
135 + c = cid.Undef
136 q.head++
137 case <-q.ctx.Done():
138 return