Skip to content

Commit

Permalink
Don't do extra work in provider queue loop
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Erik Ingenito <[email protected]>
  • Loading branch information
Erik Ingenito committed Mar 16, 2019
1 parent 6c1eca9 commit 906d2bd
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions provider/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package provider

import (
"context"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
"github.com/ipfs/go-datastore/query"
"math"
"strconv"
"strings"

cid "github.com/ipfs/go-cid"
datastore "github.com/ipfs/go-datastore"
namespace "github.com/ipfs/go-datastore/namespace"
query "github.com/ipfs/go-datastore/query"
)

// Queue provides a durable, FIFO interface to the datastore for storing cids
Expand Down Expand Up @@ -100,11 +101,16 @@ func (q *Queue) nextEntry() (datastore.Key, cid.Cid) {
// Run dequeues and enqueues when available.
func (q *Queue) work() {
go func() {
var k datastore.Key = datastore.Key{}
var c cid.Cid = cid.Undef

for {
k, c := q.nextEntry()
var dequeue chan cid.Cid
if c == cid.Undef {
k, c = q.nextEntry()
}

// If c != cid.Undef set dequeue and attempt write, otherwise wait for enqueue
var dequeue chan cid.Cid
if c != cid.Undef {
dequeue = q.dequeue
}
Expand All @@ -126,7 +132,7 @@ func (q *Queue) work() {
log.Errorf("Failed to delete queued cid %s with key %s: %s", c, k, err)
continue
}

c = cid.Undef
q.head++
case <-q.ctx.Done():
return
Expand Down

0 comments on commit 906d2bd

Please sign in to comment.