Avoid publishing data events during transaction

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2024-02-06 21:38:32 -08:00
parent 86530c0afb
commit 9eb9038a9e
3 changed files with 26 additions and 12 deletions

View File

@@ -270,6 +270,20 @@ func (m *DB) Update(fn func(*bolt.Tx) error) error {
return err
}
// Publisher returns an event publisher if one is configured
// and the current context is not inside a transaction.
func (m *DB) Publisher(ctx context.Context) events.Publisher {
_, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
if ok {
// Do no publish events within a transaction
return nil
}
if m.dbopts.publisher != nil {
return m.dbopts.publisher
}
return nil
}
// RegisterMutationCallback registers a function to be called after a metadata
// mutations has been performed.
//