/
linkremover.go
51 lines (42 loc) · 1.15 KB
/
linkremover.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// linkremover.go
package deep6
import (
"context"
"github.com/dgraph-io/badger"
"github.com/pkg/errors"
)
//
// removes all inter-object graph links from the datastore
//
// ctx - context for pipeline management
// wb - badger.WriteBatch for fast writes to db
// in - channel providing IngestData objects
//
func linkRemover(ctx context.Context, wb *badger.WriteBatch, in <-chan IngestData) (
<-chan IngestData, // new list of triples also containing links
<-chan error, // emits errors encountered to the pipeline
error) { // returns any error encountered constructing this component
out := make(chan IngestData)
errc := make(chan error, 1)
go func() {
defer close(out)
defer close(errc)
for igd := range in {
for _, t := range igd.LinkTriples {
for _, hexa := range t.SextupleLink() { // each entry as hexastore links
err := wb.Delete([]byte(hexa))
if err != nil {
errc <- errors.Wrap(err, "error removing link triples: ")
return
}
}
}
select {
case out <- igd: // pass the map onto the next stage
case <-ctx.Done(): // listen for pipeline shutdown
return
}
}
}()
return out, errc, nil
}