~mariusor/motley

9592eac020c698466e42a1cfb663977035f80502 — Marius Orcsik 3 months ago c823483
Small cleanup of LoadFromSearch contexts
2 files changed, 11 insertions(+), 10 deletions(-)

M fedbox.go
M go.mod
M fedbox.go => fedbox.go +10 -8
@@ 96,9 96,11 @@ func (f *fedbox) Load(iri pub.IRI, ff ...filters.Check) (pub.Item, error) {
			continue
		}
		col, err := st.s.Load(iri, ff...)
		if err == nil {
			return col, nil
		if err != nil {
			f.logFn("Unable to load (%s)%s: %s", st.root.GetLink(), iri, err)
			continue
		}
		return col, nil
	}
	return nil, errors.NotFoundf("unable to load %s in any storage", iri)
}


@@ 648,19 650,19 @@ func emptyAccum(_ context.Context, _ pub.CollectionInterface) error {
	return nil
}

func (a accumFn) LoadFromSearch(ctx context.Context, f *fedbox, iris ...pub.IRI) error {
func (a accumFn) LoadFromSearch(ctx context.Context, f *fedbox, iri pub.IRI, ff ...filters.Check) error {
	var cancel func()
	var g *errgroup.Group

	g, ctx = errgroup.WithContext(ctx)
	ctx, cancel = context.WithCancel(ctx)
	g, gtx := errgroup.WithContext(ctx)
	defer cancel()

	g.Go(f.searchFn(ctx, g, iri, a, ff...))

	for _, iri := range iris {
		g.Go(f.searchFn(gtx, g, iri, a))
	}
	if err := g.Wait(); err != nil {
		if errors.Is(err, StopLoad{}) {
			f.logFn("stopped loading search")
			cancel()
		} else {
			f.logFn("%s", err)
			return err

M go.mod => go.mod +1 -2
@@ 7,6 7,7 @@ require (
	github.com/charmbracelet/bubbles v0.17.1
	github.com/charmbracelet/bubbletea v0.25.0
	github.com/charmbracelet/lipgloss v0.9.1
	github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be
	github.com/go-ap/activitypub v0.0.0-20231114162308-e219254dc5c9
	github.com/go-ap/errors v0.0.0-20231003111023-183eef4b31b7
	github.com/go-ap/fedbox v0.0.0-20231114165015-41259eb71b90


@@ 32,10 33,8 @@ require (
	git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 // indirect
	git.sr.ht/~mariusor/lw v0.0.0-20230317075520-07e173563bf8 // indirect
	git.sr.ht/~mariusor/wrapper v0.0.0-20230710102058-fc38877da4fe // indirect
	github.com/atotto/clipboard v0.1.4 // indirect
	github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
	github.com/cespare/xxhash/v2 v2.2.0 // indirect
	github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
	github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
	github.com/dgraph-io/badger/v4 v4.2.0 // indirect
	github.com/dgraph-io/ristretto v0.1.1 // indirect