1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16
17 package mongo
18
19 import (
20 "context"
21 "fmt"
22
23 "perkeep.org/pkg/blob"
24 "perkeep.org/pkg/blobserver"
25
26 "go4.org/syncutil"
27 mgo "gopkg.in/mgo.v2"
28 "gopkg.in/mgo.v2/bson"
29 )
30
31 var statGate = syncutil.NewGate(50)
32
33 func (m *mongoStorage) StatBlobs(ctx context.Context, blobs []blob.Ref, fn func(blob.SizedRef) error) error {
34 return blobserver.StatBlobsParallelHelper(ctx, blobs, fn, statGate, func(b blob.Ref) (sb blob.SizedRef, err error) {
35 var doc blobDoc
36 err = m.c.Find(bson.M{"key": b.String()}).Select(bson.M{"size": 1}).One(&doc)
37 switch err {
38 case nil:
39 return blob.SizedRef{Ref: b, Size: doc.Size}, nil
40 case mgo.ErrNotFound:
41 return sb, nil
42 default:
43 return sb, fmt.Errorf("mongo: error statting %v: %v", b, err)
44 }
45 })
46 }