aboutsummaryrefslogtreecommitdiffstats
path: root/skate/cmd/skate-bref-id/main.go
blob: 21e1e9e29e42b4992e210fdb4ceb9e226c3f20ac (plain)
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
// skate-bref-id is a temporary helper to generate an id for a bref doc.
package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"runtime"
	"time"

	"git.archive.org/martin/cgraph/skate"
	"git.archive.org/martin/cgraph/skate/parallel"
	jsoniter "github.com/json-iterator/go"
)

var (
	numWorkers = flag.Int("w", runtime.NumCPU(), "number of workers")
	batchSize  = flag.Int("b", 100000, "batch size")
	json       = jsoniter.ConfigCompatibleWithStandardLibrary

	newlineB = []byte("\n")
)

func main() {
	pp := parallel.NewProcessor(os.Stdin, os.Stdout, func(p []byte) ([]byte, error) {
		var bref skate.BiblioRef
		if err := json.Unmarshal(p, &bref); err != nil {
			return nil, err
		}
		bref.Key = fmt.Sprintf("%s_%d", bref.SourceReleaseIdent, bref.RefIndex)
		bref.IndexedTs = time.Now().Unix()
		b, err := json.Marshal(bref)
		b = append(b, newlineB...)
		return b, err
	})
	pp.NumWorkers = *numWorkers
	pp.BatchSize = *batchSize
	if err := pp.Run(); err != nil {
		log.Fatal(err)
	}
}