github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/blobserver/mongo/stat.go (about)

     1  /*
     2  Copyright 2014 The Camlistore Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8       http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package mongo
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"camlistore.org/pkg/blob"
    23  	"camlistore.org/pkg/syncutil"
    24  
    25  	"camlistore.org/third_party/labix.org/v2/mgo/bson"
    26  )
    27  
    28  var statGate = syncutil.NewGate(50) // arbitrary
    29  
    30  func (m *mongoStorage) StatBlobs(dest chan<- blob.SizedRef, blobs []blob.Ref) error {
    31  	var wg syncutil.Group
    32  
    33  	for _, b := range blobs {
    34  		b := b
    35  		statGate.Start()
    36  		wg.Go(func() error {
    37  			defer statGate.Done()
    38  			var doc blobDoc
    39  			if err := m.c.Find(bson.M{"key": b.String()}).Select(bson.M{"size": 1}).One(&doc); err != nil {
    40  				return fmt.Errorf("error statting %v: %v", b, err)
    41  			}
    42  			dest <- blob.SizedRef{Ref: b, Size: doc.Size}
    43  			return nil
    44  		})
    45  	}
    46  	return wg.Err()
    47  }