v0.31.0 bf0756b

history_repo_benchmark_test.go RawHistoryFolder

1package sqlite_test
2
3import (
4	"fmt"
5	"path/filepath"
6	"testing"
7
8	"github.com/bnema/dumber/internal/domain/entity"
9	"github.com/bnema/dumber/internal/domain/repository"
10	"github.com/bnema/dumber/internal/infrastructure/persistence/sqlite"
11)
12
13// newHistoryBenchmarkRepository creates a representative local history corpus
14// outside the measured operation. Sidebar reads use GetRecent and omnibox
15// history suggestions use Search.
16func newHistoryBenchmarkRepository(b *testing.B) (repository.HistoryRepository, func()) {
17	b.Helper()
18
19	ctx := historyTestCtx()
20	db, err := sqlite.NewConnection(ctx, filepath.Join(b.TempDir(), "dumber.db"))
21	if err != nil {
22		b.Fatal(err)
23	}
24
25	b.Cleanup(func() {
26		if err := db.Close(); err != nil {
27			b.Errorf("close benchmark database: %v", err)
28		}
29	})
30
31	repo := sqlite.NewHistoryRepository(db)
32	for i := range 200 {
33		entry := &entity.HistoryEntry{
34			URL:   fmt.Sprintf("https://example%d.test/dumber/history/%d", i%20, i),
35			Title: fmt.Sprintf("Dumber history entry %d", i),
36		}
37		if err := repo.Save(ctx, entry); err != nil {
38			b.Fatal(err)
39		}
40	}
41
42	return repo, func() {}
43}
44
45func BenchmarkHistorySQLiteSidebarRecent(b *testing.B) {
46	repo, closeDB := newHistoryBenchmarkRepository(b)
47	defer closeDB()
48	ctx := historyTestCtx()
49
50	b.ReportAllocs()
51	b.ResetTimer()
52	for range b.N {
53		if _, err := repo.GetRecent(ctx, 50, 0); err != nil {
54			b.Fatal(err)
55		}
56	}
57}
58
59func BenchmarkHistorySQLiteOmniboxSearch(b *testing.B) {
60	repo, closeDB := newHistoryBenchmarkRepository(b)
61	defer closeDB()
62	ctx := historyTestCtx()
63
64	b.ReportAllocs()
65	b.ResetTimer()
66	for range b.N {
67		if _, err := repo.Search(ctx, "dumber history", 10); err != nil {
68			b.Fatal(err)
69		}
70	}
71}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close