diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/persister.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/models/persister.go b/models/persister.go index 5f79e4e..f877488 100644 --- a/models/persister.go +++ b/models/persister.go @@ -21,7 +21,15 @@ func NewPersister(log *zap.SugaredLogger, db *badger.DB) *Persister { return aso } -func (p *Persister) Store(model model) error { +func (p *Persister) StoreWithCallback(m model, onSave func()) error { + return p.storeModel(m, onSave) +} + +func (p *Persister) Store(m model) error { + return p.storeModel(m, func() {}) +} + +func (p *Persister) storeModel(model model, onSave func()) error { log := p.log.With("model", model.Name()).With("DedupKey", model.DedupKey()).With("Key", model.Key()) log.Debug("Store()") err := p.db.View(func(txn *badger.Txn) error { @@ -35,8 +43,9 @@ func (p *Persister) Store(model model) error { if updateErr != nil { return updateErr } - log.Debug("saving") + log.Debug("saving and calling storeCallback") updateErr = p.db.Update(model.SaveDedup) // stores the sha256 + onSave() } return updateErr }) |