Skip to content

Commit f487696

Browse files
committed
Parameterize the graph API to adapt parallelization and chunkSize.
1 parent 170c063 commit f487696

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

internal/client/graph_api.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,56 @@ import (
77
// GraphAPI represent the graph API from a data source point of view
88
type GraphAPI struct {
99
client *GraphClient
10+
11+
parallelization int
12+
chunkSize int
1013
}
1114

1215
// GraphAPIOptions options to pass to build graph API
1316
type GraphAPIOptions struct {
14-
URL string
15-
AuthToken string
17+
// URL to GraphKB
18+
URL string
19+
// Auth token for this data source.
20+
AuthToken string
21+
// Skip verifying the certificate when using https
1622
SkipVerify bool
23+
24+
// The level of parallelization for streaming updates, i.e., number of HTTP requests sent in parallel.
25+
Parallelization int
26+
27+
// The size of a chunk of updates, i.e., number of assets or relations sent in one HTTP request to the streaming API.
28+
ChunkSize int
1729
}
1830

1931
// NewGraphAPI create an emitter of graph
2032
func NewGraphAPI(options GraphAPIOptions) *GraphAPI {
2133
return &GraphAPI{
22-
client: NewGraphClient(options.URL, options.AuthToken, options.SkipVerify),
34+
client: NewGraphClient(options.URL, options.AuthToken, options.SkipVerify),
35+
parallelization: options.Parallelization,
36+
chunkSize: options.ChunkSize,
2337
}
2438
}
2539

2640
// CreateTransaction create a full graph transaction. This kind of transaction will diff the new graph
2741
// with previous version of it.
2842
func (gapi *GraphAPI) CreateTransaction(currentGraph *knowledge.Graph) *Transaction {
43+
var parallelization = gapi.parallelization
44+
if parallelization == 0 {
45+
parallelization = 30
46+
}
47+
48+
var chunkSize = gapi.chunkSize
49+
if chunkSize == 0 {
50+
chunkSize = 1000
51+
}
52+
2953
transaction := new(Transaction)
3054
transaction.newGraph = knowledge.NewGraph()
3155
transaction.binder = knowledge.NewGraphBinder(transaction.newGraph)
3256
transaction.client = gapi.client
3357
transaction.currentGraph = currentGraph
34-
transaction.parallelization = 30
35-
transaction.chunkSize = 1000
58+
transaction.parallelization = parallelization
59+
transaction.chunkSize = chunkSize
3660
return transaction
3761
}
3862

0 commit comments

Comments
 (0)