What changed: the Sessions page lists sessions seen only through the gateway (from the usage ledger, read-only, a native session of the same id wins), and shows in gateway mode. A Sessions switch, off by default and confirmed before it turns on, records each gateway exchange's text under the config dir (scrubbed, at most 7 days and 256 MiB, cleaned hourly). Settings sync and restore can't turn it on; POST /api/sessions/recording turns it on or off and can clear what was kept. Why: users of magpie as a gateway (gateway mode, LAN clients) had no way to see their conversations; the owner chose this design on the PR. Squashed from PR head 6a343ba1 onto origin/main. Conflicts: gui-shell.md (kept main's placeMenu text, took the PR's Sessions in gateway mode) and settings_keep_test.go (main's fields plus GatewayConversations). Run: go build ./..., go vet on gateway, gui, sessions, settings, usage; go test -race -timeout 900s on those five packages: all ok.
36 lines
807 B
Go
36 lines
807 B
Go
package usage
|
|
|
|
import (
|
|
"slices"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
var viasCache struct {
|
|
sync.Mutex
|
|
version uint64
|
|
since time.Time
|
|
value map[string][]Via
|
|
}
|
|
|
|
func cachedVias(since time.Time) map[string][]Via {
|
|
snapshot := logSnapshotFor(true)
|
|
viasCache.Lock()
|
|
defer viasCache.Unlock()
|
|
value := viasCache.value
|
|
if value == nil || viasCache.version != snapshot.version || !viasCache.since.Equal(since) {
|
|
if snapshot.uncached && len(snapshot.blocks) == 0 {
|
|
snapshot = readLogSnapshot()
|
|
}
|
|
value = buildVias(snapshot, since)
|
|
if snapshot.info != nil && snapshot.off == snapshot.info.Size() {
|
|
viasCache.version, viasCache.since, viasCache.value = snapshot.version, since, value
|
|
}
|
|
}
|
|
out := make(map[string][]Via, len(value))
|
|
for k, vs := range value {
|
|
out[k] = slices.Clone(vs)
|
|
}
|
|
return out
|
|
}
|