ingredient/info: Add Fetcher concept

This commit is contained in:
Tom Wiesing 2022-10-19 10:50:40 +02:00
parent a6501b42c7
commit 52559e4d68
No known key found for this signature in database
22 changed files with 447 additions and 328 deletions

View file

@ -141,15 +141,28 @@ func (wisski *Prefixes) filePrefixes() (prefixes []string, err error) {
var prefix = mstore.For[string]("prefix")
// Prefixes returns the cached prefixes from the given instance
func (wisski *Prefixes) PrefixesCached() (results []string, err error) {
func (wisski *Prefixes) AllCached() (results []string, err error) {
return prefix.GetAll(wisski.MStore)
}
// UpdatePrefixes updates the cached prefixes of this instance
func (wisski *Prefixes) UpdatePrefixes() error {
// Update updates the cached prefixes of this instance
func (wisski *Prefixes) Update() error {
prefixes, err := wisski.All(nil)
if err != nil {
return err
}
return prefix.SetAll(wisski.MStore, prefixes...)
}
func (prefixes *Prefixes) Fetch(flags ingredient.FetchFlags, info *ingredient.Information) (err error) {
info.NoPrefixes = prefixes.NoPrefix()
if flags.Quick {
// quick mode: grab only the cached prefixes
info.Prefixes, _ = prefixes.AllCached()
} else {
// slow mode: grab the fresh prefixes from the server
// TODO: Do we want to update them while we are at it?
info.Prefixes, _ = prefixes.All(flags.Server)
}
return
}