parallelize more List usages

This commit is contained in:
Michael Eischer
2022-10-15 17:25:45 +02:00
parent ae45f3b04f
commit 738b2a0445
3 changed files with 15 additions and 6 deletions
+5 -4
View File
@@ -7,6 +7,7 @@ import (
"os/signal"
"os/user"
"sync"
"sync/atomic"
"syscall"
"testing"
"time"
@@ -301,15 +302,15 @@ func RemoveStaleLocks(ctx context.Context, repo Repository) (uint, error) {
// RemoveAllLocks removes all locks forcefully.
func RemoveAllLocks(ctx context.Context, repo Repository) (uint, error) {
var processed uint
err := repo.List(ctx, LockFile, func(id ID, size int64) error {
var processed uint32
err := ParallelList(ctx, repo.Backend(), LockFile, repo.Connections(), func(ctx context.Context, id ID, size int64) error {
err := repo.Backend().Remove(ctx, Handle{Type: LockFile, Name: id.String()})
if err == nil {
processed++
atomic.AddUint32(&processed, 1)
}
return err
})
return processed, err
return uint(processed), err
}
// ForAllLocks reads all locks in parallel and calls the given callback.