sdk: get rid of unused error returns in wot.
This commit is contained in:
+12
-34
@@ -19,18 +19,17 @@ type wotCall struct {
|
|||||||
id uint64 // basically the pubkey we're targeting here
|
id uint64 // basically the pubkey we're targeting here
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
resultbacks []chan WotXorFilter // all callers waiting for results
|
resultbacks []chan WotXorFilter // all callers waiting for results
|
||||||
errorbacks []chan error // all callers waiting for errors
|
|
||||||
done chan struct{} // this is closed when this call is fully resolved and deleted
|
done chan struct{} // this is closed when this call is fully resolved and deleted
|
||||||
}
|
}
|
||||||
|
|
||||||
const wotCallsSize = 8
|
const wotCallsSize = 16
|
||||||
|
|
||||||
var (
|
var (
|
||||||
wotCallsMutex sync.Mutex
|
wotCallsMutex sync.Mutex
|
||||||
wotCallsInPlace [wotCallsSize]*wotCall
|
wotCallsInPlace [wotCallsSize]*wotCall
|
||||||
)
|
)
|
||||||
|
|
||||||
func (sys *System) LoadWoTFilter(ctx context.Context, pubkey nostr.PubKey) (WotXorFilter, error) {
|
func (sys *System) LoadWoTFilter(ctx context.Context, pubkey nostr.PubKey) WotXorFilter {
|
||||||
id := PubKeyToShid(pubkey)
|
id := PubKeyToShid(pubkey)
|
||||||
pos := int(id % wotCallsSize)
|
pos := int(id % wotCallsSize)
|
||||||
|
|
||||||
@@ -42,7 +41,6 @@ start:
|
|||||||
wc = &wotCall{
|
wc = &wotCall{
|
||||||
id: id,
|
id: id,
|
||||||
resultbacks: make([]chan WotXorFilter, 0),
|
resultbacks: make([]chan WotXorFilter, 0),
|
||||||
errorbacks: make([]chan error, 0),
|
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
wotCallsInPlace[pos] = wc
|
wotCallsInPlace[pos] = wc
|
||||||
@@ -56,15 +54,11 @@ start:
|
|||||||
if wc.id == id {
|
if wc.id == id {
|
||||||
// there is already a call for this exact pubkey ongoing, so we just wait
|
// there is already a call for this exact pubkey ongoing, so we just wait
|
||||||
resch := make(chan WotXorFilter)
|
resch := make(chan WotXorFilter)
|
||||||
errch := make(chan error)
|
|
||||||
wc.resultbacks = append(wc.resultbacks, resch)
|
wc.resultbacks = append(wc.resultbacks, resch)
|
||||||
wc.errorbacks = append(wc.errorbacks, errch)
|
|
||||||
wc.mutex.Unlock()
|
wc.mutex.Unlock()
|
||||||
select {
|
select {
|
||||||
case res := <-resch:
|
case res := <-resch:
|
||||||
return res, nil
|
return res
|
||||||
case err := <-errch:
|
|
||||||
return WotXorFilter{}, err
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wc.mutex.Unlock()
|
wc.mutex.Unlock()
|
||||||
@@ -76,18 +70,11 @@ start:
|
|||||||
|
|
||||||
actualcall:
|
actualcall:
|
||||||
var res WotXorFilter
|
var res WotXorFilter
|
||||||
m, err := sys.loadWoT(ctx, pubkey)
|
m := sys.loadWoT(ctx, pubkey)
|
||||||
if err != nil {
|
res = makeWoTFilter(m)
|
||||||
wc.mutex.Lock()
|
wc.mutex.Lock()
|
||||||
for _, ch := range wc.errorbacks {
|
for _, ch := range wc.resultbacks {
|
||||||
ch <- err
|
ch <- res
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res = makeWoTFilter(m)
|
|
||||||
wc.mutex.Lock()
|
|
||||||
for _, ch := range wc.resultbacks {
|
|
||||||
ch <- res
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wotCallsMutex.Lock()
|
wotCallsMutex.Lock()
|
||||||
@@ -96,23 +83,17 @@ actualcall:
|
|||||||
close(wc.done)
|
close(wc.done)
|
||||||
wotCallsMutex.Unlock()
|
wotCallsMutex.Unlock()
|
||||||
|
|
||||||
return res, err
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sys *System) loadWoT(ctx context.Context, pubkey nostr.PubKey) (chan nostr.PubKey, error) {
|
func (sys *System) loadWoT(ctx context.Context, pubkey nostr.PubKey) chan nostr.PubKey {
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
g, ctx := errgroup.WithContext(ctx)
|
||||||
g.SetLimit(45)
|
g.SetLimit(45)
|
||||||
|
|
||||||
res := make(chan nostr.PubKey)
|
res := make(chan nostr.PubKey)
|
||||||
|
|
||||||
// process follow lists
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for _, f := range sys.FetchFollowList(ctx, pubkey).Items {
|
for _, f := range sys.FetchFollowList(ctx, pubkey).Items {
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
res <- f.Pubkey
|
res <- f.Pubkey
|
||||||
|
|
||||||
@@ -123,20 +104,17 @@ func (sys *System) loadWoT(ctx context.Context, pubkey nostr.PubKey) (chan nostr
|
|||||||
for _, f2 := range ff {
|
for _, f2 := range ff {
|
||||||
res <- f2.Pubkey
|
res <- f2.Pubkey
|
||||||
}
|
}
|
||||||
wg.Done()
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Done()
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
g.Wait()
|
||||||
close(res)
|
close(res)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return res, nil
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeWoTFilter(m chan nostr.PubKey) WotXorFilter {
|
func makeWoTFilter(m chan nostr.PubKey) WotXorFilter {
|
||||||
|
|||||||
Reference in New Issue
Block a user