mirror of
https://github.com/octoleo/restic.git
synced 2024-12-24 11:55:28 +00:00
Merge pull request #867 from middelink/optimize
Optimize List() pipeline
This commit is contained in:
commit
33c8dd4ee5
@ -442,50 +442,22 @@ func (r *Repository) KeyName() string {
|
|||||||
return r.keyName
|
return r.keyName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) list(t restic.FileType, done <-chan struct{}, out chan<- restic.ID) {
|
|
||||||
defer close(out)
|
|
||||||
in := r.be.List(t, done)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// disable sending on the outCh until we received a job
|
|
||||||
outCh chan<- restic.ID
|
|
||||||
// enable receiving from in
|
|
||||||
inCh = in
|
|
||||||
id restic.ID
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
return
|
|
||||||
case strID, ok := <-inCh:
|
|
||||||
if !ok {
|
|
||||||
// input channel closed, we're done
|
|
||||||
return
|
|
||||||
}
|
|
||||||
id, err = restic.ParseID(strID)
|
|
||||||
if err != nil {
|
|
||||||
// ignore invalid IDs
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
inCh = nil
|
|
||||||
outCh = out
|
|
||||||
case outCh <- id:
|
|
||||||
outCh = nil
|
|
||||||
inCh = in
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List returns a channel that yields all IDs of type t in the backend.
|
// List returns a channel that yields all IDs of type t in the backend.
|
||||||
func (r *Repository) List(t restic.FileType, done <-chan struct{}) <-chan restic.ID {
|
func (r *Repository) List(t restic.FileType, done <-chan struct{}) <-chan restic.ID {
|
||||||
outCh := make(chan restic.ID)
|
out := make(chan restic.ID)
|
||||||
|
go func() {
|
||||||
go r.list(t, done, outCh)
|
defer close(out)
|
||||||
|
for strID := range r.be.List(t, done) {
|
||||||
return outCh
|
if id, err := restic.ParseID(strID); err == nil {
|
||||||
|
select {
|
||||||
|
case out <- id:
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPack returns the list of blobs saved in the pack id and the length of
|
// ListPack returns the list of blobs saved in the pack id and the length of
|
||||||
|
Loading…
Reference in New Issue
Block a user