Add write mutex and max connection lifetime (#1211)

This commit is contained in:
WithoutPants
2021-03-18 21:45:01 +11:00
committed by GitHub
parent 215737d6c5
commit d93011a828
2 changed files with 7 additions and 5 deletions

View File

@@ -176,17 +176,15 @@ func (t *ReadTransaction) Tag() models.TagReader {
}
type TransactionManager struct {
// only allow one write transaction at a time
c chan struct{}
}
func NewTransactionManager() *TransactionManager {
return &TransactionManager{
c: make(chan struct{}, 1),
}
return &TransactionManager{}
}
func (t *TransactionManager) WithTxn(ctx context.Context, fn func(r models.Repository) error) error {
database.WriteMu.Lock()
defer database.WriteMu.Unlock()
return models.WithTxn(&transaction{Ctx: ctx}, fn)
}