v0.2.99 4d92b3d

cache.go RawHistoryFolder

1package provider
2
3import (
4	"encoding/json"
5	"errors"
6	"os"
7	"path/filepath"
8	"time"
9)
10
11// ModelCache is the on-disk shape for discovered models.
12type ModelCache struct {
13	FetchedAt time.Time `json:"fetched_at"`
14	Models    []Model   `json:"models"`
15}
16
17// CacheTTL is how long a discovered list is considered fresh.
18const CacheTTL = 6 * time.Hour
19
20// LoadCache reads the model cache from path. Returns an empty ModelCache
21// (no error) if the file does not exist.
22func LoadCache(path string) (ModelCache, error) {
23	var c ModelCache
24	b, err := os.ReadFile(path)
25	if errors.Is(err, os.ErrNotExist) {
26		return c, nil
27	}
28	if err != nil {
29		return c, err
30	}
31	if err := json.Unmarshal(b, &c); err != nil {
32		return c, err
33	}
34	for i := range c.Models {
35		if c.Models[i].Source == "" {
36			c.Models[i].Source = "cache"
37		}
38	}
39	return c, nil
40}
41
42// SaveCache writes the cache atomically.
43func SaveCache(path string, c ModelCache) error {
44	if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
45		return err
46	}
47	b, err := json.MarshalIndent(c, "", "  ")
48	if err != nil {
49		return err
50	}
51	tmp := path + ".tmp"
52	if err := os.WriteFile(tmp, b, 0o644); err != nil {
53		return err
54	}
55	return os.Rename(tmp, path)
56}
57
58// IsFresh reports whether the cache was fetched within CacheTTL.
59func (c ModelCache) IsFresh() bool {
60	if c.FetchedAt.IsZero() {
61		return false
62	}
63	return time.Since(c.FetchedAt) < CacheTTL
64}

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 1

Tags 476

↑↓ moveenter openesc close