v0.36.0 1fb2421

ci_pullcache.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package usecase
4
5import (
6	"sync"
7
8	"bnema.dev/ermite/internal/domain"
9)
10
11// maxPullFileLists bounds the file lists the files endpoint keeps.
12const maxPullFileLists = 16
13
14// pullFilesKey names a diff by the commits it is between: it never changes, so
15// a cached list is never stale.
16type pullFilesKey struct {
17	repo       domain.RepoName
18	base, head domain.ObjectID
19}
20
21// pullFilesCache keeps the last file lists computed by the files endpoint, so
22// that the pages of one merge request (paths-filter reads them all, 100 files
23// at a time) do not each run the whole diff again. A small least recently used
24// cache: entries are the lists of at most 3000 files, and there are at most
25// maxPullFileLists of them.
26type pullFilesCache struct {
27	mu    sync.Mutex
28	items map[pullFilesKey][]domain.FileDiff
29	order []pullFilesKey // oldest use first
30}
31
32func (c *pullFilesCache) get(k pullFilesKey) ([]domain.FileDiff, bool) {
33	c.mu.Lock()
34	defer c.mu.Unlock()
35	files, ok := c.items[k]
36	if ok {
37		c.touch(k)
38	}
39	return files, ok
40}
41
42func (c *pullFilesCache) put(k pullFilesKey, files []domain.FileDiff) {
43	c.mu.Lock()
44	defer c.mu.Unlock()
45	if c.items == nil {
46		c.items = map[pullFilesKey][]domain.FileDiff{}
47	}
48	if _, ok := c.items[k]; !ok && len(c.items) >= maxPullFileLists {
49		delete(c.items, c.order[0])
50		c.order = c.order[1:]
51	}
52	c.items[k] = files
53	c.touch(k)
54}
55
56// touch makes k the most recently used. The caller holds mu.
57func (c *pullFilesCache) touch(k pullFilesKey) {
58	for i, o := range c.order {
59		if o == k {
60			c.order = append(c.order[:i], c.order[i+1:]...)
61			break
62		}
63	}
64	c.order = append(c.order, k)
65}

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 4

Tags 45

↑↓ moveenter openesc close