db batch may not be a global resource

This way db usage is safe.
This commit is contained in:
Oliver Sauder
2016-11-21 12:03:32 +01:00
committed by Lorenzo Bolla
parent f7f42a9cd8
commit 1c7c07ace7
5 changed files with 19 additions and 82 deletions
+4 -17
View File
@@ -819,15 +819,9 @@ func (collection *RemoteRepoCollection) Add(repo *RemoteRepo) error {
func (collection *RemoteRepoCollection) Update(repo *RemoteRepo) error {
batch := collection.db.CreateBatch()
err := batch.Put(repo.Key(), repo.Encode())
if err != nil {
return err
}
batch.Put(repo.Key(), repo.Encode())
if repo.packageRefs != nil {
err = batch.Put(repo.RefKey(), repo.packageRefs.Encode())
if err != nil {
return err
}
batch.Put(repo.RefKey(), repo.packageRefs.Encode())
}
return batch.Write()
}
@@ -919,14 +913,7 @@ func (collection *RemoteRepoCollection) Drop(repo *RemoteRepo) error {
delete(collection.cache, repo.UUID)
batch := collection.db.CreateBatch()
err = batch.Delete(repo.Key())
if err != nil {
return err
}
err = batch.Delete(repo.RefKey())
if err != nil {
return err
}
batch.Delete(repo.Key())
batch.Delete(repo.RefKey())
return batch.Write()
}