aboutsummaryrefslogtreecommitdiffstats
path: root/skate/cmd/skate-cluster/main.go
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-05-05 15:55:39 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-05-05 15:55:39 +0200
commit634b7b7d910ddb20c5af0722de41ef5ccded7358 (patch)
treed83f5fb36dc4c98035511059202fc51dc676ee54 /skate/cmd/skate-cluster/main.go
parenta380bffa5fb0cf20ee84ede6fa590bf38e3675f8 (diff)
parent134752c2a160986c13d6c2b9428cb2720ed382d0 (diff)
downloadrefcat-634b7b7d910ddb20c5af0722de41ef5ccded7358.tar.gz
refcat-634b7b7d910ddb20c5af0722de41ef5ccded7358.zip
Merge branch 'master' of git.archive.org:martin/cgraph
* 'master' of git.archive.org:martin/cgraph: (24 commits) update notes make: run go mod tidy after build add test for ParseUnstructured remove stub file tweaks; move parsing out of command skate-map: a bit more help output update docs set: some tweaks update README update deps start overview docs update README update docs map is a reference type fix a typo implement a few flags as mapper middleware update ignore files update deps rename skate-ref-to-release to skate-conv update README ...
Diffstat (limited to 'skate/cmd/skate-cluster/main.go')
-rw-r--r--skate/cmd/skate-cluster/main.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/skate/cmd/skate-cluster/main.go b/skate/cmd/skate-cluster/main.go
index 754eab8..de11de1 100644
--- a/skate/cmd/skate-cluster/main.go
+++ b/skate/cmd/skate-cluster/main.go
@@ -1,5 +1,5 @@
-// skate-cluster takes the (tab) output of skate-sorted-keys and generates a
-// "cluster" document, grouping docs by key. Can do some pre-filtering (e.g.
+// skate-cluster takes the (tab) output of skate-map (plus sort) and generates
+// a "cluster" document, grouping docs by key. Can do some pre-filtering (e.g.
// require refs and release docs in a single cluster).
//
// For example, this:
@@ -44,10 +44,12 @@ func main() {
batch, fields []string
keyIndex = *keyField - 1
docIndex = *docField - 1
+ line string
+ err error
)
defer bw.Flush()
for {
- line, err := br.ReadString('\n')
+ line, err = br.ReadString('\n')
if err == io.EOF {
break
}
@@ -79,16 +81,16 @@ func main() {
// containsBoth return true, if we have a ref and a non-ref item in the batch.
func containsBoth(batch []string) bool {
- var isRef int
+ var numRef int
for _, doc := range batch {
- // This is brittle. Most JSON should be in compact form, and there the
- // following chars are by convention added to distinguish a release
- // coming from a reference doc from other releases.
+ // This is brittle (but faster). Most JSON should be in compact form,
+ // and there the following chars are by convention added to distinguish
+ // a release coming from a reference doc from other releases.
if strings.Contains(doc, `"status":"ref"`) {
- isRef++
+ numRef++
}
}
- return isRef > 0 && isRef < len(batch)
+ return numRef > 0 && numRef < len(batch)
}
// writeBatch writes out a single line containing the key and the cluster values.
@@ -102,9 +104,9 @@ func writeBatch(w io.Writer, key string, batch []string) (err error) {
if *requireBoth && !containsBoth(batch) {
return nil
}
- // This is brittle, but all items in a batch are valid JSON objects, hence,
- // the following will be valid JSON as well, or will it? The key should not
- // contain a quote.
+ // This is brittle (and fast), but all items in a batch are valid JSON
+ // objects, hence, the following will be valid JSON as well, or will it?
+ // The key should not contain a quote.
_, err = fmt.Fprintf(w, "{\"k\": \"%s\", \"v\": [%s]}\n", key, strings.Join(batch, ","))
return
}