mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-07 05:42:42 +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
|
||||
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()
|
||||
|
||||
@@ -201,3 +201,13 @@ func (s *LocalRepoCollectionSuite) TestDrop(c *C) {
|
||||
|
||||
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
|
||||
func (collection *RemoteRepoCollection) Drop(repo *RemoteRepo) error {
|
||||
transaction, err := collection.db.OpenTransaction()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer transaction.Discard()
|
||||
|
||||
if _, err = transaction.Get(repo.Key()); err != nil {
|
||||
if _, err := collection.db.Get(repo.Key()); err != nil {
|
||||
if err == database.ErrNotFound {
|
||||
return errors.New("repo not found")
|
||||
}
|
||||
|
||||
+1
-7
@@ -389,13 +389,7 @@ func (collection *SnapshotCollection) Len() int {
|
||||
|
||||
// Drop removes snapshot from collection
|
||||
func (collection *SnapshotCollection) Drop(snapshot *Snapshot) error {
|
||||
transaction, err := collection.db.OpenTransaction()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer transaction.Discard()
|
||||
|
||||
if _, err = transaction.Get(snapshot.Key()); err != nil {
|
||||
if _, err := collection.db.Get(snapshot.Key()); err != nil {
|
||||
if err == database.ErrNotFound {
|
||||
return errors.New("snapshot not found")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user