lib/backup: retrieve only the required metadata when reading GCS objects

This commit is contained in:
Aliaksandr Valialkin 2019-11-19 21:06:34 +02:00
parent 355ccba81a
commit cfb9fa2100

View file

@ -67,6 +67,12 @@ func (fs *FS) String() string {
return fmt.Sprintf("GCS{bucket: %q, dir: %q}", fs.Bucket, fs.Dir)
}
// selectAttrs contains object attributes to select in ListParts.
var selectAttrs = []string{
"Name",
"Size",
}
// ListParts returns all the parts for fs.
func (fs *FS) ListParts() ([]common.Part, error) {
dir := fs.Dir
@ -74,6 +80,9 @@ func (fs *FS) ListParts() ([]common.Part, error) {
q := &storage.Query{
Prefix: dir,
}
if err := q.SetAttrSelection(selectAttrs); err != nil {
return nil, fmt.Errorf("error in SetAttrSelection: %s", err)
}
it := fs.bkt.Objects(ctx, q)
var parts []common.Part
for {