Don't use transactions when direct db access is enough

For read-only action transactions are not necessary and they risk to deadlock
if multiple go-routines try to read the database.
This commit is contained in:
Lorenzo Bolla
2021-08-24 11:15:39 +02:00
parent fd83c1a5bf
commit 2fa3adee1d
4 changed files with 17 additions and 18 deletions
+5 -4
View File
@@ -237,12 +237,13 @@ func (collection *LocalRepoCollection) Len() int {
// Drop removes remote repo from collection
func (collection *LocalRepoCollection) Drop(repo *LocalRepo) error {
transaction, err := collection.db.OpenTransaction()
if err != nil {
if _, err := collection.db.Get(repo.Key()); err != nil {
if err == database.ErrNotFound {
return errors.New("local repo not found")
}
return err
}
defer transaction.Discard()
delete(collection.cache, repo.UUID)
batch := collection.db.CreateBatch()