all repos — searchix @ a49d405f81ed9b872ae638832f3a1a5f2339780c

Search engine for NixOS, nix-darwin, home-manager and NUR users

internal/importer/main_test.go (view raw)

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
52
53
package importer

import (
	"context"
	"testing"

	"alin.ovh/searchix/internal/config"
	"alin.ovh/searchix/internal/file"
	"alin.ovh/searchix/internal/index"
	"alin.ovh/searchix/internal/manpages"
	"alin.ovh/x/log"
)

var cfg = config.DefaultConfig

func BenchmarkImporterLowMemory(b *testing.B) {
	tmp, err := file.OpenRoot(b.TempDir())
	if err != nil {
		b.Fatal(err)
	}

	logger := log.Configure(false)
	_, write, _, err := index.OpenOrCreate(tmp, false, &index.Options{
		LowMemory: true,
		BatchSize: cfg.Importer.BatchSize,
		Logger:    logger.Named("index"),
	})
	if err != nil {
		b.Fatal(err)
	}

	imp, err := New(&cfg, &Options{
		Logger:     logger.Named("importer"),
		LowMemory:  true,
		WriteIndex: write,
		Manpages: manpages.New(&manpages.Options{
			Logger: logger.Named("manpages"),
			Root:   tmp,
		}),
	})
	if err != nil {
		b.Fatal(err)
	}

	err = imp.Start(
		context.Background(),
		false,
		&[]string{"nixpkgs"},
	)
	if err != nil {
		b.Fatal(err)
	}
}