mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-03 05:00:56 +00:00
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:
+5
-4
@@ -237,12 +237,13 @@ func (collection *LocalRepoCollection) Len() int {
|
|||||||
|
|
||||||
// Drop removes remote repo from collection
|
// Drop removes remote repo from collection
|
||||||
func (collection *LocalRepoCollection) Drop(repo *LocalRepo) error {
|
func (collection *LocalRepoCollection) Drop(repo *LocalRepo) error {
|
||||||
transaction, err := collection.db.OpenTransaction()
|
if _, err := collection.db.Get(repo.Key()); err != nil {
|
||||||
if err != nil {
|
if err == database.ErrNotFound {
|
||||||
|
return errors.New("local repo not found")
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer transaction.Discard()
|
|
||||||
|
|
||||||
delete(collection.cache, repo.UUID)
|
delete(collection.cache, repo.UUID)
|
||||||
|
|
||||||
batch := collection.db.CreateBatch()
|
batch := collection.db.CreateBatch()
|
||||||
|
|||||||
@@ -201,3 +201,13 @@ func (s *LocalRepoCollectionSuite) TestDrop(c *C) {
|
|||||||
|
|
||||||
c.Check(s.collection.Drop(repo1), ErrorMatches, "local repo not found")
|
c.Check(s.collection.Drop(repo1), ErrorMatches, "local repo not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *LocalRepoCollectionSuite) TestDropNonExisting(c *C) {
|
||||||
|
repo := NewLocalRepo("local3", "Comment 3")
|
||||||
|
|
||||||
|
_, err := s.collection.ByUUID(repo.UUID)
|
||||||
|
c.Check(err, ErrorMatches, "local repo .* not found")
|
||||||
|
|
||||||
|
err = s.collection.Drop(repo)
|
||||||
|
c.Check(s.collection.Drop(repo), ErrorMatches, "local repo not found")
|
||||||
|
}
|
||||||
|
|||||||
+1
-7
@@ -898,13 +898,7 @@ func (collection *RemoteRepoCollection) Len() int {
|
|||||||
|
|
||||||
// Drop removes remote repo from collection
|
// Drop removes remote repo from collection
|
||||||
func (collection *RemoteRepoCollection) Drop(repo *RemoteRepo) error {
|
func (collection *RemoteRepoCollection) Drop(repo *RemoteRepo) error {
|
||||||
transaction, err := collection.db.OpenTransaction()
|
if _, err := collection.db.Get(repo.Key()); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer transaction.Discard()
|
|
||||||
|
|
||||||
if _, err = transaction.Get(repo.Key()); err != nil {
|
|
||||||
if err == database.ErrNotFound {
|
if err == database.ErrNotFound {
|
||||||
return errors.New("repo not found")
|
return errors.New("repo not found")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-7
@@ -389,13 +389,7 @@ func (collection *SnapshotCollection) Len() int {
|
|||||||
|
|
||||||
// Drop removes snapshot from collection
|
// Drop removes snapshot from collection
|
||||||
func (collection *SnapshotCollection) Drop(snapshot *Snapshot) error {
|
func (collection *SnapshotCollection) Drop(snapshot *Snapshot) error {
|
||||||
transaction, err := collection.db.OpenTransaction()
|
if _, err := collection.db.Get(snapshot.Key()); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer transaction.Discard()
|
|
||||||
|
|
||||||
if _, err = transaction.Get(snapshot.Key()); err != nil {
|
|
||||||
if err == database.ErrNotFound {
|
if err == database.ErrNotFound {
|
||||||
return errors.New("snapshot not found")
|
return errors.New("snapshot not found")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user