Documentation
¶
Overview ¶
Package prefs owns the prefs table: the user's settings and the app state that has no table of its own, each stored as text under a string key.
Any package may read any key, but every key has exactly one writer:
- settings writes the user's settings, among them the clone root and the other repository locations (clones.root and clones.locations), and the rules that the trust, snooze, sensitive, notifyprefs, branchrules, reporules, integrationprefs, threadrules, and statusprefs packages declare and decode (trust.*, snooze.*, files.*, notify.*, branches.*, repos.*: the pinned and muted repositories and orgs, integrations.*, scripts.*: the scripts.magexTargets and scripts.repoFiles switches of Repo scripts' sources, and scripts.lastPage and scripts.lastRepo, where the Scripts tab and Repo scripts reopen, threadrules.*: whether the user's GitHub notifications are read, and whether, how, and when they are cleared, status.*: which status pages the service status check reads, and which of each one's parts it watches, and update.mode, which updateprefs declares: what the app does when a new version is out).
- inbox writes inbox.*: the account and status of the last refresh, and the cached avatar.
- prompts writes prompts.*: the default prompts and the starters already added.
- budget writes budget.*: the API budget's state between runs, through core's keeper.
- integrations writes tools.*: each tool's last detection and latest release.
- release writes release.*: the Release page's last list and the repository locations it was read from, which the next start shows at once.
- hooks writes hooks.*: whether a checks run has ended, after which the Hooks page folds what it says about the tools the checks install.
- ghthreads writes ghthreads.*: ghthreads.sync, the state of the passes that mirror the user's GitHub notifications (the account read last, page 1's ETag and the high-water mark the next pass starts from, GitHub's poll interval, the last pass and the last walk of every page, whether GitHub lets the token read them and when a refused listing is sent again, the last error, whether the walk stopped at the newest 1,000, whether the next pass walks every page, the fingerprint of the clearing rules the last pass queued under, and how many clears it held back for review).
- setup writes setup.*: whether the first-run setup is done (setup.done), which it decides once per database at startup, and the step the user was on (setup.step), where it opens again.
- update writes every update.* key but update.mode: when it last checked (update.lastCheck), the last version it told of (update.notified), the banner hidden with Later (update.bannerHiddenUntil), the version the app last ran as (update.lastRunRelease), the install a restart began, read and cleared at the next start (update.pendingInstall), and the last five releases that failed to install for good, by version and SHA-512, which no check downloads or offers again (update.uninstallable).
A Store from New runs each call on the pool. One joined to a transaction with WithTx runs every call inside it, so prefs are written together with another owner's tables and roll back with them. Update reads a value and writes the next one in a single transaction, which the store begins IMMEDIATE, so two updates of one key never lose either change.
Index ¶
- type Store
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Get(ctx context.Context, key string) (value string, ok bool, err error)
- func (s *Store) GetList(ctx context.Context, key string) (list []string, ok bool, err error)
- func (s *Store) GetMany(ctx context.Context, keys ...string) (map[string]string, error)
- func (s *Store) Set(ctx context.Context, key, value string) error
- func (s *Store) SetList(ctx context.Context, key string, list []string) error
- func (s *Store) SetMany(ctx context.Context, values map[string]string) error
- func (s *Store) Update(ctx context.Context, key string, ...) error
- func (s *Store) WithTx(tx *sql.Tx) *Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes the prefs table.
func New ¶
New returns a Store over the pool db. Each write stamps the row's updated_at from c; a nil c is the system clock.
func (*Store) Delete ¶
Delete removes the value stored under key, so readers fall back to their default. A key with no value is not an error.
func (*Store) Get ¶
Get returns the value stored under key. ok is false, with an empty value, when none is stored.
func (*Store) GetList ¶
GetList returns the list stored under key as a JSON array of strings. ok is false, with a nil list, when no value or an empty one is stored. A value that is not such an array is an error.
func (*Store) GetMany ¶
GetMany returns the values stored under keys, by key. A key with no value is left out, and no keys read nothing.
func (*Store) SetList ¶
SetList stores list under key as a JSON array; a nil list is stored as an empty one.
func (*Store) SetMany ¶
SetMany stores each value under its key, all of them or none: they are written in one transaction, or in the one the Store joined, and share one updated_at.
func (*Store) Update ¶
func (s *Store) Update(ctx context.Context, key string, fn func(value string, ok bool) (string, error)) error
Update replaces the value stored under key with what fn returns for it. fn gets the stored value and whether there is one; the read and the write run in one transaction, or in the one the Store joined, so no other write to the key comes between them. When fn returns an error, nothing is written and Update returns that error as it is.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
Package prefval reads and writes the two shapes of value most preferences hold: a switch, stored as a boolean, and a list, stored as a JSON array of strings.
|
Package prefval reads and writes the two shapes of value most preferences hold: a switch, stored as a boolean, and a list, stored as a JSON array of strings. |