mirror of https://github.com/perkeep/perkeep.git
blobserver/mongo, missing index on "key"
The mongo blobserver does not ensure an index on "key" key which stores the blobref. It is slow and enumerate fails when there are too many blobs because mongodb can't sort when there are too many results. Change-Id: Id644a48f93be308007f77cf5ea6b6620acf489bd
This commit is contained in:
parent
2bde109c41
commit
b18a28edd1
|
@ -69,13 +69,24 @@ func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (blobserver.Stora
|
||||||
return newMongoStorage(cfg)
|
return newMongoStorage(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var uniqueKeyIndex = mgo.Index{
|
||||||
|
Key: []string{"key"},
|
||||||
|
Unique: true,
|
||||||
|
DropDups: false,
|
||||||
|
Background: false,
|
||||||
|
Sparse: false,
|
||||||
|
}
|
||||||
|
|
||||||
func newMongoStorage(cfg config) (blobserver.Storage, error) {
|
func newMongoStorage(cfg config) (blobserver.Storage, error) {
|
||||||
session, err := getConnection(cfg.url())
|
session, err := getConnection(cfg.url())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c := session.DB(cfg.database).C(cfg.collection)
|
c := session.DB(cfg.database).C(cfg.collection)
|
||||||
|
err = c.EnsureIndex(uniqueKeyIndex)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return blobserver.Storage(&mongoStorage{c: c}), nil
|
return blobserver.Storage(&mongoStorage{c: c}), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue